android - Could Not Retrive any Response Data from Given URL -


i can retrieve json data same code failed retrieve data url, why not returning response code or not coming data response. please me resolve this, or suggest me how retrieve non json data web url.

   url uniprotfasta = new url(ur);   url = "http://www.uniprot.org/uniprot/p69905.fasta";   url uniprotfasta = new url(ur);  httpurlconnection conn = (httpurlconnection) uniprotfasta.openconnection();     conn.connect();     int response = conn.getresponsecode();     log.e("response code * *", string.valueof(response));     inputstream = conn.getinputstream();     // convert inputstream string     string contentasstring = readit(is, 500);     log.e("httpurlcon * *",contentasstring); 

i have tried 1 received nothing in response.

string data = ""; urlconnection conn = uniprotfasta.openconnection(); bufferedreader reader = new bufferedreader(new inputstreamreader(conn.getinputstream())); string line = ""; while((line = reader.readline()) != null){      data += line; } log.e("data * *",data); 

okay have tried you.

  1. write code in asyntask.

    public class testurl extends asynctask<void, void, void> {  @override protected void doinbackground(void... params) {     string url = "http://www.uniprot.org/uniprot/p69905.fasta";     httpurlconnection conn = null;     inputstream = null;     try {         url uniprotfasta = new url(url);         conn = (httpurlconnection) uniprotfasta.openconnection();         conn.connect();         int response = conn.getresponsecode();         log.e("response code * *", string.valueof(response));         = conn.getinputstream();     } catch (ioexception e) {         e.printstacktrace();     }     // convert inputstream string     string contentasstring = convertstreamtostring(is);     log.e("httpurlcon * *", contentasstring);      return null; } 
  2. function convert input stream string

    private string convertstreamtostring(inputstream is) { bufferedreader reader = new bufferedreader(new inputstreamreader(is)); stringbuilder sb = new stringbuilder();  string line = null; try {     while ((line = reader.readline()) != null) {         sb.append(line).append('\n');     } } catch (ioexception e) {     e.printstacktrace(); } {     try {         is.close();     } catch (ioexception e) {         e.printstacktrace();     } } return sb.tostring(); 

    }

  3. give permission in manifest file

    <uses-permission android:name="android.permission.internet" /> 
  4. execute asynctask run code in background thread.

    new testurl().execute(); 
  5. response

    e/response code * *: 200 e/httpurlcon * *: >sp|p69905|hba_human hemoglobin subunit alpha os=homo    sapiens gn=hba1 pe=1 sv=2           mvlspadktnvkaawgkvgahageygaealermflsfpttktyfphfdlshgsaqvkghg           kkvadaltnavahvddmpnalsalsdlhahklrvdpvnfkllshcllvtlaahlpaeftp           avhasldkflasvstvltskyr 

i hope you.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -