使用httpclient 4.0.1添加用户代理

时间:2017-11-10 15:04:27

标签: java jenkins

我需要使用库httpclient 4.0.1

添加用户代理
    HttpClientParams httpparams= new HttpClientParams();
    HttpClient httpclient = new HttpClient(httpparams);
    string userAgent = "my user agent";
    if (userAgent != null && userAgent.length() != 0) {
        httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    }

我收到此错误消息:

错误:

找不到符号httpclient.getParams()。setParameter(CoreProtocolPNames.USER_AGENT,userAgent);

符号:

变量CoreProtocolPNames

1 个答案:

答案 0 :(得分:0)

import org.apache.http.params.CoreProtocolPNames;