How to set custom User-Agent with apache http client library 4.1?

前端 未结 3 582
深忆病人
深忆病人 2020-12-08 02:03

How to make HTTPClient use custom User-Agent header?

The following code submits empty user-agent. What am I missing?

import java.io.IOException;

imp         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 02:44

    You can also set a global user agent value instead of per request:

    String userAgent = "NewUseAgent/1.0";
    HttpClient httpClient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
    

提交回复
热议问题