鍍金池/ 問(wèn)答/數(shù)據(jù)分析&挖掘  Java  網(wǎng)絡(luò)安全/ java爬蟲:httpClient發(fā)起請(qǐng)求時(shí)報(bào)ClientProtocolExc

java爬蟲:httpClient發(fā)起請(qǐng)求時(shí)報(bào)ClientProtocolException的錯(cuò)誤

背景:

java爬蟲抓取某保險(xiǎn)網(wǎng)站的數(shù)據(jù)。

問(wèn)題:

在模擬登錄之后,對(duì)目標(biāo)頁(yè)面發(fā)起請(qǐng)求時(shí)報(bào)錯(cuò)。

登陸成功。。。。。
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

出錯(cuò)代碼位置:

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");

    // 報(bào)錯(cuò)位置
    HttpResponse response = HttpUtils.httpClient.execute(httpUriRequest);

初接觸爬蟲,請(qǐng)問(wèn)各位大大為什么會(huì)出錯(cuò)?求指教?。?/p>

先在此謝過(guò)。

回答
編輯回答
孤島
Caused by: org.apache.http.ProtocolException: Content-Length header already present

你是不是指定 Content-Length 頭了

2017年9月4日 02:21