简体   繁体   中英

Apache HTTP Client socks proxy

I am currently working at a web requests project and I am using Apache Http Client library. I try to connect to a server (Eg http://www.google.com ) with an working Socks v4/5 tested with mozilla firefox but the problem is that I never get a response. Only different errors...

Here is a code snippet:

//HttpClient
DefaultHttpClient http = new DefaultHttpClient();
//A class defined by me
Proxy proxy = bla bla;
HttpHost host = new HttpHost(proxy.getIP(), proxy.getPort());
if (proxy.getUsername() != null) {
   http.getCredentialsProvider().setCredentials(
                            new AuthScope(proxy.getIP(), proxy.getPort()),
                            new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()));
}
http.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);

Can anyone tell a proper way to initiate comunnication through SOCKS proxies? Thanks!

Note: The code above works perfect with HTTP proxies.

Http proxy and socks proxy has very different protocols ( http://en.wikipedia.org/wiki/SOCKS#Comparison ). For your question: You can do thTis by native java socket ( How can I configure HTTPClient to authenticate against a SOCKS proxy? ) or create your own implementation over DefaultClientConnectionOperator, here is good guide ( http://4devops.blogspot.com/2011/10/httphttps-over-socks-proxy-with-java.html )

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