2011-05-19 55 views
0

我使用HTTPUrlConnection與GET方法從服務器獲取數據,並返回字符串大約13k字符,但我只接收1228個字符。如何超過get方法返回字符串(httpurlconnection)

任何超過接收所有字符的解決方案?

這是我的代碼:

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

如何向我們展示您在做什麼?對GET請求的HTTP響應不是(或不應該)在長度上受到限制。 – 2011-05-19 16:23:28

+0

代碼請.... – 2011-05-19 16:23:30

+0

可能相關:[HTTP URI GET限制](http://stackoverflow.com/questions/266322/http-uri-get-limit) – MarcoS 2011-05-19 16:25:52

回答

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);