Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
- 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 + "nContry: " + country + "n############################################"+"n");
- }
Add Comment
Please, Sign In to add comment