Vae 东 2020-04-08 11:19 采纳率: 0%
浏览 180
已结题

HttpClient访问线上服务器访问网站第一次就需要输入验证码.频率太快了,如何设置访问频率?

public String getResult(String url) {
HttpClientBuilder builder = HttpClientBuilder.create();
CloseableHttpClient httpClient = builder.build();
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
if (httpResponse == null) {
httpGet.abort();
log.warn("响应为空: url" + url);
} else {
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != 203){
httpGet.abort();
log.warn("请求失败, 返回状态码为:" + httpResponse.getStatusLine().getStatusCode() + ", 并中断get请求" + url);
} else {
log.info("当前状态码为:" + statusCode);
// 有响应并且返回为203
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
InputStream inputStream = httpResponse.getEntity().getContent()) {
try {
if (inputStream == null) {
return null;
}
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inputStream.read(buffer)) > 0) {
byteStream.write(buffer, 0, len);
}
} catch (IOException e) {
log.error("读取流异常", e);
}
return new String(byteStream.toByteArray());

                    } catch (IOException ex) {
                        log.error("关闭流异常", ex);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2020-04-08 12:06
    关注
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月17日

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端