我在使用 apache http client 库发送 http 请求时,遇到了一个奇怪的问题

2021-11-04 16:13:54 +08:00
 JCJD

对于我发送的 http 请求的说明(如果需要其它信息,我随时补充):

post 请求

Content-Type: application/json

Content-Length: 1277

如果我在发送给请求的时候,加上 Expect: 100-continue 这个 header ,请求就会成功;没有这个 header 请求就失败 SocketTimeoutException ,错误日志:

java.net.SocketTimeoutException : Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
 	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
 	at java.net.SocketInputStream.read(SocketInputStream.java:171)
 	at java.net.SocketInputStream.read(SocketInputStream.java:141)
 	at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
 	at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
 	at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282)
 	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
 	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
 	at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
 	at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
 	at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165)
 	at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
 	at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
 	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
 	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
 	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
 	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
 	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
 	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
 	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)

我重复了很多次,携带 headerExpect: 100-continue就成功,不带就失败(偶尔也会成功)。

实在搞不懂为什么,求教 v 友

496 次点击
所在节点    问与答
1 条回复
jxxz
2021-11-04 18:12:39 +08:00
这个 read timeout ,有可能是服务端的问题

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/813063

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX