How to use an HTTP proxy in java

后端 未结 3 2041
灰色年华
灰色年华 2020-12-02 20:44

I am writing a code that connects to websites and checks some code, like a crawler. But I need to connect trough a proxy and change the IP address (so it doesn\'t show the c

3条回答
  •  日久生厌
    2020-12-02 21:26

    Or you can also use HttpClient which would suit your needs better. Check out the documentation, it's brief and very informative.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    
    HttpHost proxy = new HttpHost("someproxy", 8080);
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    

提交回复
热议问题