3

I am new to android. I am getting an error while updating through HttpClient like java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

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();

        }

Please help me. I also tried

System.setProperty("http.keepAlive", "false"); 

but it's not working.

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
Viresh
  • 323
  • 2
  • 5
  • 17
  • 1
    the answer was that it's the server's fault - it had to close the connection after each request . it might be that android keeps a pool of connections and use the old one or something like that – Jitesh Upadhyay Feb 11 '14 at 10:29

1 Answers1

8

Set the http.keepAlive system property to false before issuing any HTTP requests.

System.setProperty("http.keepAlive", "false");
Lendl Leyba
  • 2,287
  • 3
  • 34
  • 49