【问题标题】:Why does the SocketTimeoutException error disappear after adding the expect: 100-continue request header为什么添加expect: 100-continue请求头后SocketTimeoutException错误消失
【发布时间】:2021-11-04 13:52:24
【问题描述】:

我在使用apache http客户端时遇到了SocketTimeoutException错误,但是添加请求头expect: 100-continue后,请求成功。我多次重复请求,结果都是一样的。

这是我的 http 请求信息:

发布方法

内容类型:application/json

内容长度:1277

我的服务类型:基于spring的web服务

他们的服务类型:基于 aps.net 的网络服务

以下是错误日志:

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)

我知道添加请求头expect: 100-continue后,会在真正的http请求之前发送一个http请求。但我不明白为什么这个标头可以解决我的 SocketTimeoutException 错误。帮帮我,谢谢。

【问题讨论】:

  • 如果您使用其他 HTTP 客户端发送请求会怎样?例如,POST-man(或任何其他 REST 客户端)...
  • 我试过 postman 和 curl 都成功了。

标签: java httprequest


【解决方案1】:

我发现你的问题很有趣。我第一次听说这样的标题Expect ...阅读后,使用这些链接:

  1. Expect Header
  2. Continue-100 Response
  3. Expect Headerpurpose/use
  4. Expect header in ASP net

我的结论是aps.net-based web service 期待这样的标头...如果您不发送它,则服务(或在本例中为应用程序服务器)不会发送 HTTP 错误代码,而是丢弃已建立的连接并且您在读取任何响应时都会收到 SocketTimeoutException(注意:这只是推测。使用其他 HTTP 客户端和网络嗅探器可以更清楚地说明这一点)...

【讨论】:

  • 我尝试使用 postman 和 curl 发送相同的 http 请求,他们都成功了。另外,我发现 postman 没有携带 'Expect: 100-continue',而 curl 携带了 'Expect: 100-continue'。所以它似乎与'Expect:100-continue'无关,我仍然很困惑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-19
  • 2022-11-21
  • 2013-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多