Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proxy detected when using java

Tags:

java

i checked this page and got some usefull code for using a proxy in java code when connecting to a webpage.

I can confirm that pages like whatsmyip do indeed tell me that proxy is working - it is showing proxy ip. The problem is that the page i am accesing to in java code, somehow detects my true ip and blocks content. I do know how it does that (header, return ip, etc.), what i do not know is how to bypass that.

Maybe another interesting thing is that this page works with no problems using 1 of the best known online proxy sites - it shows content. Now what is even more interesting is that i tried taking that sites ip and used it as proxy in my program, but there it didn't work - true ip got detected, which is really strange.

edit: This is my new code:

System.setProperty("java.net.useSystemProxies","false");
    System.setProperty("http.proxyHost", "94.230.208.147");                                      
    System.setProperty("http.proxyPort", "9001");   
    System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");    

    System.setProperty("https.proxyHost", "94.230.208.147");                                      
    System.setProperty("https.proxyPort", "9001");   
    System.setProperty("https.nonProxyHosts", "localhost|127.0.0.1");

I can confirm that https://whatsmyip.com/ isn't fooled by this proxy and can see my true ip. What did i forget to include ?

like image 812
Jessica Avatar asked Mar 10 '26 00:03

Jessica


1 Answers

Add this at the end of your code:

System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");

That indicates the hosts that should be accessed without going through the proxy. Typically this defines internal hosts. The value of this property is a list of hosts, separated by the '|' character.

like image 110
Jonathan Gagne Avatar answered Mar 12 '26 17:03

Jonathan Gagne