我使用Jodd Http库连接代理:
ProxyInfo proxyInfoObj = new ProxyInfo(ProxyType.HTTP, "10.30.56.70", 8080, "", "");
SocketHttpConnectionProvider provider = new SocketHttpConnectionProvider();
provider.useProxy(proxyInfoObj);
HttpRequest request = HttpRequest.get(url);
request.method("GET");
request.charset("UTF-8");
HttpResponse response = request.open(provider).send();
result = response.bodyText();
但我收到了这个错误:
jodd.http.HttpException: HTTP: Invalid code
at jodd.http.net.HTTPProxySocketFactory.createHttpProxySocket(HTTPProxySocketFactory.java:113)
at jodd.http.net.HTTPProxySocketFactory.createSocket(HTTPProxySocketFactory.java:32)
如果我使用SOCKS4类型,程序会挂起并且不会返回任何内容。任何人都可以帮助我吗?
但我可以使用以下代码通过代理连接:
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.30.56.70", 8080));
HttpURLConnection connection =(HttpURLConnection)new URL("http://tvl.csmtalk.vn/api/sms/receive").openConnection(proxy);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "text/xml");
connection.setRequestProperty("Accept", "text/xml, application/xml");
connection.setRequestMethod("GET");
connection.connect();
答案 0 :(得分:0)
对我来说,两个代码都挂了。当我尝试Jodd时,它会挂起,因为它无法打开10.30.56.70:8080
的代理套接字。当我尝试
telnet 10.30.56.70 8080
从命令行它也会挂起。看起来代理没有响应。 (如果您需要更多详细信息,或者如果您想发送一些有关连接的私人数据,您可以联系Jodd支持。)
顺便说一下,你不需要:
request.method("GET");
request.charset("UTF-8");
因为方法已由方法GET
设置为get()
,并且charset不用于请求,而是响应(如果未由服务器设置则设置为1)。