Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP request through SOCKS protocol

I am trying to use Socks5 proxies to make http post requests. The provider for the proxies has disabled http or something. I get the following error;

Exception in thread "main" java.net.SocketException: SOCKS: Connection not allowed by ruleset

I am using the code

    System.setProperty("java.net.socks.username", user);
    System.setProperty("java.net.socks.password", pass);

    Proxy prox = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(ip, 8000));
    URL url = new URL("https://www.myip.com");
    URLConnection con = url.openConnection(prox);

    con.setConnectTimeout(10000);
    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

    String line;
    while ((line = in.readLine()) != null) {
        System.out.println(line);
    }
    in.close();

How do I tunnel(?) this http request through the proxy?

PS I know this is possible because some extension in firefox allows me to use the proxy too I have also tried this code, but it results in the same error : https://pastebin.com/xt6evbm7

like image 520
Mark Cockram Avatar asked Sep 18 '26 10:09

Mark Cockram


1 Answers

This system does not use the system properties.

        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(user, pass.toCharArray());
            }
        });
like image 71
Mark Cockram Avatar answered Sep 20 '26 23:09

Mark Cockram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!