request latency httpClient

The client may first send a request to the server, if the server returns a status code 100, the client may continue to send a data request to the server body. In some cases this can reduce network overhead.

再看看HttpClient里面对100-Continue的说明:
The purpose of the Expect: 100-Continue handshake is to allow the client that is sending a request message with a request body to determine if the origin server is willing to accept the request (based on the request headers) before the client sends the request body. The use of the Expect: 100-continue handshake can result in a noticeable performance improvement for entity enclosing requests (such as POST and PUT) that require the target server’s authentication. The Expect: 100-continue handshake should be used with caution, as it may cause problems with HTTP servers and proxies that do not support HTTP/1.1 protocol.

Inside word is mentioned 100-Continue should be used with caution, because some servers do not support, it may cause some problems. So the cause of my experience because the server does not support, cause the client has to wait until after the 100-Continue request times out and only then request body sent to the server.
As for the version of the problem is that because HttpClient 3.1 and HttpClient 4.1.2 have been put off by default 100-Continue lost, only in HttpClient 4.0.1 is turned on by default, I wonder is HttpClient document which says this It should be used with caution, why by default?
Solution
Solution one: Of course, of course, the easiest solution is to replace the HttpClient version, according to the HttpClient ReleaseNotes, 4.1 future versions will have been turned off by default 100-Continue out.
Solution two: another solution is to give 100-Continue 4.0.1 will close off:
HttpProtocolParams.setUseExpectContinue (the params, to true); to HttpProtocolParams.setUseExpectContinue (params, false);
This will turn off the function expectContinue
or
1httppost.getParams () setBooleanParameter (CoreProtocolPNames.USE_EXPECT_CONTINUE, false ).;

Solution three: If you want to make sure 100-Continue driving, you can shorten the 100-Continue timeout, the default timeout period is a maximum of 3 seconds, you can be set by the following methods:
. 1httppost.getParams () setIntParameter (CoreProtocolPNames.WAIT_FOR_CONTINUE, 100);

original link: https: //blog.csdn.net/qq_25958497/article/details/81985996

Guess you like

Origin www.cnblogs.com/muxi0407/p/11589512.html