我使用HTTPUrlConnection和GET方法从服务器获取数据,返回字符串大约有13k个字符,但我只收到1228个字符。
任何超出接收所有字符的解决方案?
这是我的代码:
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());
答案 0 :(得分:2)
您只是阅读输入的一行。
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);