android - EOFException and FileNotFoundException in HttpURLConnection getInputStream() -


when trying connect http://ws.audioscrobbler.com/2.0/ post data using httpurlconnection, (randomly)

eofexception 

or

filenotfoundexception: http://ws.audioscrobbler.com/2.0/ 

on nexus 4 running android 4.2.2.

anybody can help?

edit

i upgraded 4.3: same issue.

public inputstream getdata(string url_str, list<namevaluepair> postdata) {      map<string, object> response = new hashmap<string, object>();      inputstream = null;     httpurlconnection conn = null;      try {          url url = new url(url_str);          conn = (httpurlconnection) url.openconnection();         conn.setreadtimeout(connection_timeout);         conn.setconnecttimeout(read_timeout);         conn.setrequestmethod("post");         conn.setdoinput(true);                                if(postdata != null){              conn.setdooutput(true);              outputstream os = conn.getoutputstream();             bufferedwriter writer = new bufferedwriter( new outputstreamwriter(os, "utf-8"));             writer.write(getquery(postdata));             writer.close();             os.close();         }           // starts query          conn.connect();           // , return response          = conn.getinputstream();                       return is;      } catch (ioexception e) {          // ...      } {          if(conn != null){             conn.disconnect();         }          if (is != null) {             try {                 is.close();             } catch (ioexception e) {                 e.printstacktrace();             }         }      } }   private string getquery(list<namevaluepair> params) throws unsupportedencodingexception {     stringbuilder result = new stringbuilder();     boolean first = true;      (namevaluepair pair : params)     {         if (first)             first = false;         else             result.append("&");          result.append(urlencoder.encode(pair.getname(), "utf-8"));         result.append("=");         result.append(urlencoder.encode(pair.getvalue(), "utf-8"));     }      return result.tostring(); } 

i checked conn.getresponsecode() , 403. exception might due that.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -