Setting user agent of a java URLConnection

后端 未结 4 844
陌清茗
陌清茗 2020-11-22 16:11

I\'m trying to parse a webpage using Java with URLConnection. I try to set up the user-agent like this:

java.net.URLConnection c = url.openConnection();
c.se         


        
4条回答
  •  温柔的废话
    2020-11-22 17:13

    its work for me set the User-Agent in the addRequestProperty.

    URL url = new URL();
    HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
    httpConn.addRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0");
    

提交回复
热议问题