0

有时 httpclient 在服务器接受之前尝试将 http 发布到服务器。我不知道会发生哪种情况,但由于此问题发布失败。为什么客户会这样?

这是日志的一部分;

DEBUG org.apache.http.wire - >> "POST       /destination-path[\r][\n]"
DEBUG org.apache.http.wire - >> "Content-Length: 594[\r][\n]"
DEBUG org.apache.http.wire - >> "Content-Type: application/json[\r][\n]"
DEBUG org.apache.http.wire - >> "Host: url:port[\r][\n]"
DEBUG org.apache.http.wire - >> "Connection: Keep-Alive[\r][\n]"
DEBUG org.apache.http.wire - >> "Expect: 100-continue[\r][\n]"
DEBUG org.apache.http.wire - >> "[\r][\n]"
DEBUG org.apache.http.headers - >> POST /destination-path HTTP/1.1
DEBUG org.apache.http.headers - >> Content-Length: 594
DEBUG org.apache.http.headers - >> Content-Type: application/json
DEBUG org.apache.http.headers - >> Host: url:port
DEBUG org.apache.http.headers - >> Connection: Keep-Alive
DEBUG org.apache.http.headers - >> Expect: 100-continue
DEBUG org.apache.http.wire - >> "data:mydata"

“>>”表示此日志中的传出操作。这意味着客户端正在向服务器发送握手请求。最后一条语句,正在尝试发送数据。但它应该等待服务器对此连接的响应。通常,此问题发生在初始连接时。尝试此失败的连接后的连接是成功的。

4

1 回答 1

3

RFC 2616 第 8.2.3 节:

   Because of the presence of older implementations, the protocol allows
   ambiguous situations in which a client may send "Expect: 100-
   continue" without receiving either a 417 (Expectation Failed) status
   or a 100 (Continue) status. Therefore, when a client sends this
   header field to an origin server (possibly via a proxy) from which it
   has never seen a 100 (Continue) status, the client SHOULD NOT wait
   for an indefinite period before sending the request body.

当使用“期望:继续”握手时,Apache HttpClient 在发送请求正文之前等待 2000 毫秒以获得 4xx 或 100 状态。可以使用“http.protocol.wait-for-continue”参数来指定不同的值。

于 2012-10-03T15:43:00.493 回答