我正在尝试使用 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/