无法通过代理发出请求 [英] Unable to make a request via proxy
本文介绍了无法通过代理发出请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过代理提出请求.这在没有代理的情况下工作正常:
I want to make a request via a proxy. This, with no proxy, works fine:
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);
//............................
但是这个,使用代理,效果不佳,它挂起:
But this, with a proxy, isn't working well, it hangs:
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();
//............................
这是怎么回事?
推荐答案
正如@MrSimpleMind 已经说过的:使用 Proxy.Type.HTTP
而不是 Proxy.Type.SOCKS
.
As @MrSimpleMind already stated: Use Proxy.Type.HTTP
instead of Proxy.Type.SOCKS
.
这篇关于无法通过代理发出请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文