我想通过代理提出请求。这没有代理,工作正常:
Socket sock = new Socket("example.com", 80);
OutputStream oStream = sock.getOutputStream();
//Writing headers to send to the proxy
String request = rType + " " + uri + " HTTP/1.0";
oStream.write(request.getBytes());
oStream.write(endOfLine.getBytes());
String cmd = "host: "+ header.get("host");
oStream.write(cmd.getBytes());
oStream.write(endOfLine.getBytes());
System.out.println(cmd);
//............................
但是,使用代理服务器,这种情况并不顺利,它会挂起:
Proxy prx = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("my proxy ip address", 1234)); // predefined ip and port
sock = new Socket(prx);
sock.connect(new InetSocketAddress("example.com", 80)); //hangs here
oStream = sock.getOutputStream();
//............................
该怎么做?
答案 0 :(得分:0)
正如@MrSimpleMind已说明:使用Proxy.Type.HTTP
代替Proxy.Type.SOCKS
。