Okhttp 在代理连接关闭后发送 http 请求
Okhttp sending http request after proxy connection is closed
我正在通过代理传送我的请求,它似乎每 10-15 秒关闭一次连接。因此,如果客户端请求一个网站并且需要一些时间,连接可能会关闭,因此 okhttp 库会抛出 "unexpected end of stream"。即使连接已关闭并且库抛出该异常,服务器已成功接收到请求,但客户端无法检查答案。如果我尝试在没有代理的情况下请求相同的 url 我没有问题并且我成功收到了答案。
在这里你可以看到它的wireshark:
wireshark capture
在照片的最后你可以看到客户端在 19:27:54,980 发出的请求,然后在 10 秒后,客户端收到了 FIN tcp 数据包。所以在那之后 Okhttp 抛出这个异常:
java.io.IOException: unexpected end of stream on Connection{m.apuestas.codere.es:443, proxy=HTTP @ /185.163.232.127:58542 hostAddress=/185.163.232.127:58542 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1}
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.telecobets.http.HTTPClient$LoggingInterceptor.intercept(HTTPClient.java:219)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.telecobets.http.HTTPClient$AddHeadersInterceptor.intercept(HTTPClient.java:199)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:188)
at com.main(Main.java:375)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:237)
at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
... 26 more
不是服务器关闭了连接,因为我一直在同时向不同的服务器发出不同的请求,突然同时连接被关闭了。
所以我的问题是,即使连接被代理服务器关闭,是否有办法接收该答案?
整个 wireshark 捕获是 here
代理IP:185.163.232.127:58542
代理服务器提供商每 10 秒断开一次连接。
我正在通过代理传送我的请求,它似乎每 10-15 秒关闭一次连接。因此,如果客户端请求一个网站并且需要一些时间,连接可能会关闭,因此 okhttp 库会抛出 "unexpected end of stream"。即使连接已关闭并且库抛出该异常,服务器已成功接收到请求,但客户端无法检查答案。如果我尝试在没有代理的情况下请求相同的 url 我没有问题并且我成功收到了答案。 在这里你可以看到它的wireshark: wireshark capture
在照片的最后你可以看到客户端在 19:27:54,980 发出的请求,然后在 10 秒后,客户端收到了 FIN tcp 数据包。所以在那之后 Okhttp 抛出这个异常:
java.io.IOException: unexpected end of stream on Connection{m.apuestas.codere.es:443, proxy=HTTP @ /185.163.232.127:58542 hostAddress=/185.163.232.127:58542 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1}
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)
at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.telecobets.http.HTTPClient$LoggingInterceptor.intercept(HTTPClient.java:219)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at com.telecobets.http.HTTPClient$AddHeadersInterceptor.intercept(HTTPClient.java:199)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
at okhttp3.RealCall.execute(RealCall.java:77)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:188)
at com.main(Main.java:375)
Caused by: java.io.EOFException: \n not found: limit=0 content=…
at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:237)
at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
... 26 more
不是服务器关闭了连接,因为我一直在同时向不同的服务器发出不同的请求,突然同时连接被关闭了。 所以我的问题是,即使连接被代理服务器关闭,是否有办法接收该答案?
整个 wireshark 捕获是 here
代理IP:185.163.232.127:58542
代理服务器提供商每 10 秒断开一次连接。