0

I work with HttpUrlConnection in my App and in my common Java Test and I implemented a method and that Method (common for both of them, so, identical!!!) behaves in Android case in another way.

Both of them can right receive an identical response from Server but in Java Test I can show this response while in Android App is chunked to 3200 Chars.

That's my Code

private String sendPost() throws Exception{


    String url = "http://www.something.com/my_page.jsp?";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    //add request header
    con.setRequestMethod("POST");


    String urlParameters ="param1=val1&param2=val2";

    // Send post request
    con.setDoOutput(true);
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    // return result
    Log.i("TAG", "sendPost:: Response length : " + response.length()); // <- This line returns the same length!!!       

    return response.toString();
}

All I can get of this object con from Class HttpUrlConnection like ContentLength, ContentType, etc is the same in both of these cases, therefore I suspect, there must be an intern Setting/Parameter of String/StringBuffer in Android, which distinguishes these case but I don't know what. readLine reads the same or at least the same number of chars cause the length of response is the same in both of cases.

If you could say me, what is wrong, I'd be very thankful.

Kind Regards

Gödel77
  • 839
  • 3
  • 15
  • 27
  • 3
    Are you logging the string returned from this methods somewhere? I suppose the logcat might limit the length of the logged message. – Natix Oct 10 '14 at 10:55
  • Thx @Natix, that was! Please, write your comment as Answer and I select it as answer. – Gödel77 Oct 10 '14 at 11:05

1 Answers1

2

I can't understand your description of the symptoms; i.e. why you think that something is being truncated.

However, I can assure you that it is NOT due to a limit on the length of String or StringBuffer.

Those two classes do have a limit, but it is 2**31 (i.e. >2 billion) characters. You will typically get an OutOfMemoryError before your buffer gets that big.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 1
    I think that, because when I show my Log and it shows just 3200 and the advice of @Natix has solved, it was a "Logcat" Limitation. – Gödel77 Oct 10 '14 at 11:04