MADforFUNandHappy MADforFUNandHappy - 1 month ago 8
Java Question

I can't get the response for my POST request, if I try to get anything from the response it will get stuck and timeout

( I use the following code to passthrough a POST or GET request, however it will allways get stuck if I try to retrieve anything from the POST Response and timeout after some time. GET request and response are no problem.

What am I doing wrong ? )

Edit:

I just increased the timeout time on the client side and i get
"IOExceptionjava.net.SocketException: Unexpected end of file from Server"
Why this is only thrown if a POST is sent i don't know yet.

Edit2:

After further research of this error,
there are a lot of posts about this but I do not see why GET would work while POST isn't.

Edit3:

For some reason on the Serverside the content-length is 0 even though this Header was send and recieved. By adding connection.setChunkedStreamingMode();
when sending a POST request i get the Response from the Server, however I stil don't know why it's not working with the content-length Header.

Answer

In case anyone wants to know why Setting "connection.setChunkedStreamingMode()" did the trick.

The Client could send a request using http 1.0 or 1.1 but http 1.1 requests don't work with the content-length header added to it (which was added someware in the process). On the contrary the chunked mode does work for http 1.0 as well.

I tested this after I found this post from Clement Amarnath How do i send a POST request without Transfer Encoding:chunked from Jersey ReST Client 2.22.2

Comments