获取java.net.SocketException:recvfrom失败:ECONNRESET(由对等方重置连接)

Vir*_*esh 2 java android

我是android的新手.通过HttpClient更新时遇到错误,如java.net.SocketException:recvfrom失败:ECONNRESET(连接由对等方重置)

public static String newupdateProf(String memid, String gender,
                String pdata, String dob, String pimg) throws IOException,
                JSONException {
            // System.setProperty("http.keepAlive", "false");
            final HttpClient httpClient = new DefaultHttpClient();
            final HttpPost httpost = new HttpPost(websrv.trim() + "/newUpdtProf");

            JSONStringer img = new JSONStringer().object().key("prof").object()
                    .key("memid").value(memid.trim()).key("gender")
                    .value(gender.trim()).key("pdata").value(pdata.trim())
                    .key("dob").value(dob.trim()).key("pimg").value(pimg.trim())
                    .endObject().endObject();
            StringEntity se = new StringEntity(img.toString());
            httpost.setEntity(se);
            httpost.setHeader("Accept", "application/json");
            httpost.setHeader("Content-type", "application/json");

            HttpResponse httpResponse = httpClient.execute(httpost);

            HttpEntity httpEntity = httpResponse.getEntity();

            InputStream stream = httpEntity.getContent();
            String result = convertStreamToString(stream);
            return result.trim();

        }
Run Code Online (Sandbox Code Playgroud)

请帮我.我也试过了

System.setProperty("http.keepAlive", "false"); 
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

Lei*_*yba 7

在发出任何HTTP请求之前,将http.keepAlive系统属性设置为false.

System.setProperty("http.keepAlive", "false");
Run Code Online (Sandbox Code Playgroud)

  • 它对我有用.但他的回答是什么解释? (7认同)