-
Notifications
You must be signed in to change notification settings - Fork 38.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"GET must not have a request body" exception with OkhttpClient and BufferingClientHttpRequestFactory #32612
Comments
Do you see the same behavior with okhttp3? While okhttp4 is binary compatible, we don't support this version of the library officially. Also, we have deprecated this request factory entirely, see #30919. Can you reproduce the same behavior with a public API like httpbin.org? It would be easier for us to investigate the issue if we can reproduce the problem using a sample app that you could provide. |
I haven't tested with okhttp3 or public API yet , and I can give it a try。 and I can provide another Information : the same API like I described above, I have tested with httpclient5,and Get、Post request work ok with BufferingClientHttpRequestFactory
|
I have finish test,with public API:https://httpbin.org/get ,still getting an error
and All scenes i use okHttp3.14.9,It's the same situation |
I Trace the source code,in spring-web(6.1.5) the error throws at spring's OkHttp3ClientHttpRequest ->executeInternal() ->builder.method(this.method.name(), requestBody) and At this time,requestBody is not null,it has body and headers two nodes,and body's running type is BufferingClientHttpRequestWrapper . body has two nodes too , the first is bufferedOutput ,and it’s value is not null but an Empty array,I don't know if it's a problem here |
My project use springboot3.1.8 (spring-web 6.0.16) , and I use RestTemplate with Okhttp4.12.0 for making calls to REST endpoints , the initialize code as follows :
and the call code as follows :
the result as follows:
and when I upgrade my springboot version to 3.2.4(spring-web 6.1.5) , the same code run result as follows:
After upgrade , Get request work ok,but post request work error,and then I found the change(spring-web 6.1.X) in wiki
To reduce memory usage in RestClient and RestTemplate, most ClientHttpRequestFactory implementations no longer buffer request bodies before sending them to the server. As a result, for certain content types such as JSON, the contents size is no longer known, and a Content-Length header is no longer set. If you would like to buffer request bodies like before, simply wrap the ClientHttpRequestFactory you are using in a BufferingClientHttpRequestFactory.
so I change My initialize code as follows :
and I run my code again ,the result as follows:
I found , After change(using BufferingClientHttpRequestFactory) , post request work ok , but get request work wrong
so did I miss some configuration? or is there any other suggestions for modifications?
The text was updated successfully, but these errors were encountered: