Android的HttpURLConnection的抛EOFException类Android、HttpURLConnection、EOFException

2023-09-04 04:50:47 作者:慕心倾寒

下面是在最简单的方式的问题。

Here's the question in simplest way.

我创建通过代理服务器使用的HttpURLConnection对象HTTPS连接到我的服务器。

I create a HTTPS connection to my server through proxy using HttpUrlConnection Object.

我的代理服务器将关闭连接,但我的code仍然尝试重用相同的连接。所以,我得到EOFException类。

My proxy closes the connection but my code still tries to reuse the same connection. And so I get EOFException.

我如何处理这类案件?

推荐答案

我会建议禁用http.keepalive系统属性。在文档的性能部分表示套接字连接将被重用时可能。这听起来就像是试图重用连接,但代理已经关闭了它。在这个帖子,达雷尔还表明,改变系统特性解决了他的问题。

I'd recommend disabling the http.keepalive system property. The performance section of the documentation indicates that socket connections will be reused when possible. It sounds like it is trying to reuse the connection, but the proxy has already closed it. On this post, Darrell also indicates that changing the system property solved his problem.

System.setProperty("http.keepAlive", "false");
 
精彩推荐
图片推荐