Vihaari Varma
Vihaari Varma

Reputation: 155

Maximum HttpUrlConnection Response

I am using HttpUrlConnection to get JSON strings from web, but the response is good for smaller strings but not for larger ones: this is what I am seeing in my app, and this is the data from server to a web page I did not include any HTML from server side.

Here is my code:

URL adr = new URL("http://placeform.tk/forapp.php");
HttpURLConnection connection =(HttpURLConnection) adr.openConnection();
connection.connect();
int rcode = connection.getResponseCode();
Log.d("rcode",Integer.toString(rcode));
if (rcode == HttpURLConnection.HTTP_OK) {
    InputStream inputStreamReader = connection.getInputStream();
    String c = connection.getHeaderField("content-length");
    Reader rd = new InputStreamReader(inputStreamReader);
    Log.d("contentsize", Integer.toString(connection.getContentLength()) + c);
    chars = new char[connection.getContentLength()];
    Log.d("contentsize", Integer.toString((int)connection.getContentLength()) + c);
    rd.read(chars);
    String output = new String(chars);

Upvotes: 0

Views: 318

Answers (1)

Aiyaz Parmar
Aiyaz Parmar

Reputation: 562

use this link and add that class in your project and call webservice from that class. cause that class will build up your response string with use of string builder. have a look at that class. and comment if you have any problem.

Upvotes: 1

Related Questions