2

我使用 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();
4

1 回答 1

1

对我来说,两个代码都挂起。当我尝试 Jodd 时,它挂起,因为它无法打开代理套接字到10.30.56.70:8080. 当我尝试

telnet 10.30.56.70 8080

从命令行它也挂起。看起来代理没有响应。(如果您需要更多详细信息,或者如果您想发送一些有关连接的私人数据,您可以联系 Jodd 支持。)

顺便说一句,你不需要:

request.method("GET");
request.charset("UTF-8");

因为方法已经GET被方法设置为get(),字符集不用于请求,而是响应(如果服务器没有设置,则设置一个)。

于 2014-08-30T04:11:19.463 回答