android - How to adjust the code to download full size content? -
how download full size content. followed android connecting network tutorial , mentioning int len = 500; it's downloading 500 character api returns more character. how adjust code download full content ?
below code having ...
private string downloadurl(string myurl) throws ioexception { inputstream = null; // display first 500 characters of retrieved // web page content. int len = 500; try { url url = new url(myurl); httpurlconnection conn = (httpurlconnection) url.openconnection(); conn.setreadtimeout(10000 /* milliseconds */); conn.setconnecttimeout(15000 /* milliseconds */); conn.setrequestmethod("get"); conn.setdoinput(true); // starts query conn.connect(); int response = conn.getresponsecode(); = conn.getinputstream(); // convert inputstream string string contentasstring = readit(is, len); return contentasstring; // makes sure inputstream closed after app // finished using it. } { if (is != null) { is.close(); } } } // reads inputstream , converts string. public string readit(inputstream stream, int len) throws ioexception, unsupportedencodingexception { reader reader = null; reader = new inputstreamreader(stream, "utf-8"); char[] buffer = new char[len]; reader.read(buffer); return new string(buffer); }
i event tried increasing len value 5000 , having same problem.
you can try instead of or inside public string readit
bufferedreader r = new bufferedreader(new inputstreamreader(is)); stringbuilder total = new stringbuilder(); string line; while ((line = r.readline()) != null) { total.append(line); } string resultstring = total.tostring()
Comments
Post a Comment