【发布时间】:2021-06-04 16:24:22
【问题描述】:
我通过http 库访问了一个休息端点并将响应转换为字符串(如下所示),然后将其写入HDFS(Hadoop 分布式文件系统)。
HttpClient httpclient = new HttpClient();
HttpGet httpget = new HttpGet(url);
HttpResponse response= httpclient.execute(httpget);
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
String respStr = content.toString();
我意识到虽然 REST API 以毫秒为单位响应,但由于上述将响应转换为字符串的代码,它需要很多时间。
有人可以建议如何加快行为或如何以正确的方式进行吗?
【问题讨论】:
-
可能是 API 正在使用流进行响应吗?那是第一个字节被快速发送但需要时间来获得完整的响应?您是否尝试过 cURL 或类似工具?
标签: java rest httpclient http-get