【问题标题】:HTTP request through SOCKS protocol通过 SOCKS 协议的 HTTP 请求
【发布时间】:2019-01-18 12:01:21
【问题描述】:

我正在尝试使用 Socks5 代理来发出 http 发布请求。代理的提供者已禁用 http 或其他东西。 我收到以下错误;

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

我正在使用代码

    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();

我如何通过代理隧道(?)这个 http 请求?

PS 我知道这是可能的,因为 Firefox 中的某些扩展也允许我使用代理 我也试过这段代码,但它会导致同样的错误:https://pastebin.com/xt6evbm7

【问题讨论】:

    标签: java http proxy http-proxy socks


    【解决方案1】:

    本系统不使用系统属性。

            Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(user, pass.toCharArray());
                }
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多