简体   繁体   中英

Java Jodd Http Client with proxy

I used Jodd Http library to connect with the proxy:

    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();

But i got this error:

    jodd.http.HttpException: HTTP: Invalid code
    at jodd.http.net.HTTPProxySocketFactory.createHttpProxySocket(HTTPProxySocketFactory.java:113)
    at jodd.http.net.HTTPProxySocketFactory.createSocket(HTTPProxySocketFactory.java:32)

If I use SOCKS4 type, the program hang and don't return anything. Can anyone help me?

But I can connect via proxy using following code:

   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();

For me both codes hangs. When I try Jodd, it hangs because it can not open proxy socket to 10.30.56.70:8080 . When I try to

telnet 10.30.56.70 8080

from command line it hangs as well. It looks like proxy is not responding. (You can contact Jodd support if you need more details, or if you want to send some private data regarding the connectivity.)

btw, you don't need to:

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

as method is already set to GET by method get() and charset is not used for requests, but response (to set one if not set by server).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM