gpt4 book ai didi

java - 获取网页内容

转载 作者:行者123 更新时间:2023-11-30 11:52:56 25 4
gpt4 key购买 nike

我正在尝试从 URL 获取 XML 内容:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://www.domain.com/test.aspx"));
HttpResponse response = client.execute(request);
in = response.getEntity().getContent();

当我写出响应内容时,在内容末尾之前被截断了。

有什么想法吗?

最佳答案

您是否为输入流 in 使用了 InputStreamReader

String s = "";
String line = "";
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
try {
while ((line = rd.readLine()) != null) { s += line; }
} catch (IOException e) {
// Handle error
}

// s should be the complete string

关于java - 获取网页内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6575166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com