Connect to a site using proxy code in java

后端 未结 3 911
北荒
北荒 2021-01-03 05:53

I want to connect to as site through proxy in java. This is the code which I have written:

public class ConnectThroughProxy 
{
    Proxy proxy = new Proxy(Pr         


        
3条回答
  •  执念已碎
    2021-01-03 06:23

    It seems to me, that you are not using your Proxy instance at all. I think you should pass it when you are creating URLConnection instance:

    URLConnection connection=url.openConnection(proxy);
    

    Setting of environment properties http.proxy is easier and when using some 3rd party libraries without Proxy instance passing support only possible solution, but its drawback is that it is set globally for the whole process.

提交回复
热议问题