2

I'm in trouble with similar issue described at Unable to tunnel through proxy - Jsoup. Trying to connect with test page I'm getting such a exeption:

Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"

My ProxyAuthenticator class:

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class ProxyAuthenticator extends Authenticator{

private String userName, password;

protected PasswordAuthentication getPasswordAuthentication(){
    return new PasswordAuthentication(userName,password.toCharArray());
}

public ProxyAuthenticator(String userName, String password){
    this.userName = userName;
    this.password = password;
}

and my proxy configuration with sample code

public static void main(String args[]) throws IOException, InterruptedException {

    Authenticator.setDefault(new ProxyAuthenticator("myUserName@somemail.com", "mySecretPassword"));
    System.setProperty("https.proxyHost", "VPNServerHostname");
    System.setProperty("https.proxyPort", "VPNServerPort");

    Document doc = Jsoup.connect("https://tools.keycdn.com/geo" )
            .timeout(30000)
            .userAgent("Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2")
            .get();

        String ip = doc.select("th:contains(IP) + td").text();
        String isp = doc.select("th:contains(Hostname) + td").text();
        String provider = doc.select("th:contains(Provider) + td").text();
        String country = doc.select("th:contains(Country) + td").text();


        System.out.println("IP: " + ip + "\nHostname: " + isp + "\nProvider: " + provider + "\nCountry: " + country + "\n############################################"+"\n");

}

Could you please help?

lo0p3r
  • 39
  • 6
  • @Io0p3r, which proxy service are you using? I tried your code, it worked for me first and then got the same error. – Abhilash Jun 25 '18 at 18:53
  • @Abhilash, I'm using one of many Nord VPN servers. Trying to connect via UDP or TCP, but with no success till now :( Maybe I'm using incorrect port number... – lo0p3r Jun 25 '18 at 19:47
  • I've just set `jdk.http.auth.tunneling.disabledSchemes=` and `jdk.http.auth.proxying.disabledSchemes=` in /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/net.properties file and it started to work! – lo0p3r Jun 25 '18 at 20:53

0 Answers0