我正在尝试通过 Java 中的 SOCKS (v4 / v5) 代理创建 http 请求。在 WikiPedia 上阅读 socks 通信协议后,我将这段代码放在一起:
Socket sock = new Socket();
InetSocketAddress remoteProxyAddress = new InetSocketAddress(proxy ip, proxy port);
sock.connect(remoteProxyAddress, connTimeout);
InputStream in = sock.getInputStream();
OutputStream out = sock.getOutputStream();
out.write(0x04);
out.write(0x01);
out.write((endpoint.getPort() >> 8) & 0xff);
out.write((endpoint.getPort() >> 0) & 0xff);
out.write(endpoint.getAddress().getAddress());
out.write(0x0);
out.flush();
这是我从代理服务器读取的部分。问题是响应总是“-1”。
我已经在 Firefox 上尝试过代理,它运行良好。所以...问题出在我的应用程序中。
谁能帮我?谢谢!