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.

「expect: continue」ハンドシェイクを使用する場合、Apache HttpClient は、リクエスト本文を送信する前に 4xx または 100 ステータスを 2000 ミリ秒待機します。「http.protocol.wait-for-continue」パラメータを使用して別の値を指定できます。

于 2012-10-03T15:43:00.493 に答える