背景:
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
头了
添加回答
举报
0/150
提交
取消