0

I am getting connection reset by peer error when trying to get the input stream from a server. How do i resolve it ? I didn't get this error for a week ago but suddenly today i don't know what went wrong.Here is a piece of code where i am getting the error

   URL url = new URL(urls[0]);
   URLConnection conn = url.openConnection();
   //check="1";workng
   conn.setDoOutput(true); 
   //check="1";wrkng
   OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); 
   //check="1";wrkng
   wr.write( data );   
   wr.flush(); 

   reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
   check="1"; **not wrkng**
   StringBuilder sb = new StringBuilder();
   String line = null;
   while((line = reader.readLine()) != null)
   {
                           sb.append(line + " ");

   }

Content = sb.toString(); In my log file it shows "file /data/data/com.nvidia.nvcplsvc/files/driverlist.txt not found " error. Does this error got anything to do with ?

user1547566
  • 403
  • 1
  • 6
  • 11
  • Could you try URLConnection's setDoInput method? "conn.setDoInput(true)" – nurisezgin Mar 23 '14 at 09:26
  • not working... but when i run my android app on another android device the following error appears in logcat : "error opening trace file . No such file is found...." – user1547566 Mar 23 '14 at 09:35
  • OK, why did you use apache Http API(HttpClient)? – nurisezgin Mar 23 '14 at 09:37
  • i copied the code from some source and modified to suit my need. – user1547566 Mar 23 '14 at 09:41
  • If you give more detail about your code and what do you want, I help you – nurisezgin Mar 23 '14 at 09:45
  • ok i have a final String url ="xyz.in" which i am passing as an argument to the following code : – user1547566 Mar 23 '14 at 09:49
  • ok, i have a final string ="xyz.in" and a static request_code(int) which i am passing string as an argument to an async task in which if the request code =0 , then the string data="&"++ URLEncoder.encode("data", "UTF-8") + "="+request_code; so the final url is "xyz.in/&data=0" .By which i am connecting to the server and getting data – user1547566 Mar 23 '14 at 09:56

1 Answers1

0

If you want send data to server and get result by this data, could you try this block?

HttpClient client = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(url[0]);
postMethod.setEntity(new StringEntity(data));
String result = EntityUtils.toString(client.execute(postMethod).getEntity());
nurisezgin
  • 1,530
  • 12
  • 19