2015-07-21 67 views
1

提出請求我想要通過代理的請求。這與無代理,做工精細:無法通過代理

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

你肯定Proxy.Type.SOCKS而不是Proxy.Type.HTTP? – MrSimpleMind

+0

@MrSimpleMind,對不起,當我用「HTTP」我的錯誤是** java.lang.IllegalArgumentException異常:無效的代理** –

+0

@MrSimpleMind,代理本身存在並正常工作。 –

回答

0

正如@MrSimpleMind所述:使用Proxy.Type.HTTP而不是Proxy.Type.SOCKS