0

I use HTTPUrlConnection with GET method to get data from the server, and the return string about 13k characters, but I'm just receive 1228 characters.

Any solution to exceed to receive all characters?

This is my code:

URL con = new URL(url);
HttpURLConnection httpURLCon = (HttpURLConnection)con.openConnection();
DataInputStream inStream = new DataInputStream(httpURLCon.getInputStream());
Scanner sc = new Scanner(inStream);
String response = sc.next();
System.out.prinlnt(response.length());
Leo
  • 1,433
  • 23
  • 40
  • How about showing us what you're doing? The HTTP response to your GET request isn't (or shouldn't be) limited in length. – Mark Elliot May 19 '11 at 16:23
  • possibly related: [HTTP URI GET limit](http://stackoverflow.com/questions/266322/http-uri-get-limit) – MarcoS May 19 '11 at 16:25
  • Wouldn't sc.next() just give the first token, i.e the first line? – Captain Giraffe May 19 '11 at 18:05
  • OK, I've found my solution, Captain Giraffe is right, sc.next() just given the first token, and the first token is not all the first line if the first line is very long(as in my case). So I change sc.next() to sc.nextLine(), and the problem is solved. Thanks! – Leo May 19 '11 at 18:18

1 Answers1

2

You are just reading one line of the input.

int contentLength = 0;
while( sc.hasNext() ){
    String aLine = sc.next();
    contentLength += aLine.length();
    // process the line would be a good idea here, perhaps appending a StringBuffer
}
System.out.prinlnt(contentLength);
Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67