java - 通过 SOCKS 协议(protocol)的 HTTP 请求

标签 java http proxy http-proxy socks

我正在尝试使用 Socks5 代理来发出 http post 请求。代理提供商已禁用 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

最佳答案

此系统不使用系统属性。

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

关于java - 通过 SOCKS 协议(protocol)的 HTTP 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54253625/

相关文章:

java - eclipse 上 tomcat 8 的问题

java在抽象方法中返回抽象类

Python请求代理连接超时

java - 如何在 Clojure 中代理具有重载方法的 Java 类?

c - 如何创建一个简单的代理来访问 C 中的 Web 服务器

java - Spring数据cassandra : No property builder found on class User to bind constructor to

java - XML Creation using java 翻译 HTML Entity 中的 CR

python - 如何从 Windows 定期创建 HTTP POST 请求

使用 Web 服务器作为负载均衡器时的 Java Web session cookie 路径问题

validation - 在 go 中验证 http 请求的惯用方法