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

前端 未结 3 576
深忆病人
深忆病人 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:41

    The line

    request.setHeader("User-Agent", "MySuperUserAgent");

    is missing. Add it and enjoy.

提交回复
热议问题