调试了一段httpclient.executeMethod(method);请求第三方api的代码,一直报错:java.net.SocketException: Connection reset
后来换成HttpPost,还是报错java.net.SocketException: Connection reset
再设置请求配置
httpPost.setHeader(HTTP.CONN_DIRECTIVE,HTTP.CONN_CLOSE);
httpPost.setProtocolVersion(org.apache.http.HttpVersion.HTTP_1_0);
还是报错java.net.SocketException: Connection reset
最后找到大神的说明:是因为jdk1.7的问题,换成1.8就可以了。
网友评论