为了账号安全,请及时绑定邮箱和手机立即绑定

java爬虫:httpClient发起请求时报ClientProtocolException的错误

java爬虫:httpClient发起请求时报ClientProtocolException的错误

MM们 2019-02-18 08:55:20
背景: java爬虫抓取某保险网站的数据。 问题: 在模拟登录之后,对目标页面发起请求时报错。 登陆成功。。。。。 org.apache.http.client.ClientProtocolException at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) at spider.SimulatePALogin.afterLoginPager(SimulatePALogin.java:92) at spider.SimulatePALogin.main(SimulatePALogin.java:41) Caused by: org.apache.http.ProtocolException: Content-Length header already present at org.apache.http.protocol.RequestContent.process(RequestContent.java:96) at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:182) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ... 4 more Process finished with exit code 0 出错代码位置: HttpUriRequest httpUriRequest = new HttpPost( "https://icore-pts.pingan.com.cn/ebusiness/login"); // ?Accept?: application/json, text/javascript, */*; q=0.01 httpUriRequest.setHeader("Host","pacas-login.pingan.com.cn"); //...... set headers here httpUriRequest.setHeader("Upgrade-Insecure-Requests","1"); httpUriRequest .setHeader( "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36"); // 报错位置 HttpResponse response = HttpUtils.httpClient.execute(httpUriRequest); 初接触爬虫,请问各位大大为什么会出错?求指教!! 先在此谢过。
查看完整描述

1 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

Caused by: org.apache.http.ProtocolException: Content-Length header already present

你是不是指定 Content-Length 头了

查看完整回答
反对 回复 2019-03-01
  • 1 回答
  • 0 关注
  • 6816 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信