Connect to a site using proxy code in java

后端 未结 3 923
北荒
北荒 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:26

    I was using the Google Data APIs and the only way I got the proxy settings to work was to provide ALL the parameters related to proxy, even thought they are set to be empty:

    /usr/java/jdk1.7.0_04/bin/java -Dhttp.proxyHost=10.128.128.13 
        -Dhttp.proxyPassword -Dhttp.proxyPort=80 -Dhttp.proxyUserName 
        -Dhttps.proxyHost=10.128.128.13 -Dhttps.proxyPassword -Dhttps.proxyPort=80 
        -Dhttps.proxyUserName com.stackoverflow.Runner
    

    Where, username and password are NOT required, and the same http and https servers are set to be the same, as well as the port number (if that's your case as well). Note that the same HTTP proxy is also provided as the HTTPS server, as well as its port number (reference from https://code.google.com/p/syncnotes2google/issues/detail?id=2#c16).

    If your Java class has an instance of the class "URL", it should pick those configurations up...

提交回复
热议问题