用httpclient访问后台接口报错java.net.SocketException: Software caused connection abort: recv failed,百度了一圈都说是由于服务器端关闭了连接,说是因为长连接的问题,于是我就把httpclient的请求设置为短连接
HttpPost httpPost=new HttpPost(url); httpPost.setProtocolVersion(HttpVersion.HTTP_1_0); httpPost.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
但是问题还是存在java.net.SocketException: Connection reset,后来想着是服务器端关闭了连接才想到代码里用了多线程,公用的代码没有做同步,于是把httpclient公用方法加synchronized关键字,问题解决