如何超出get方法的返回字符串(httpurlconnection)

发布于 2024-11-08 15:27:48 字数 424 浏览 0 评论 0原文

我使用 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());

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守不住的情 2024-11-15 15:27:48

您只是读取一行输入。

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文