How can I configure HTTPClient to authenticate against a SOCKS proxy?

前端 未结 5 1328
死守一世寂寞
死守一世寂寞 2021-01-03 04:39

I need to set up proxy authentication against a SOCKS proxy. I found out this post giving instructions that appear to work with common HTTP proxies.

                 


        
5条回答
  •  感动是毒
    2021-01-03 04:50

    SOCKS is not supported by HttpClient 3 natively. You can try the SOCKS support in JDK as suggested by others. The side effect is that your whole JVM will go through the same SOCKS proxy.

    Java 5 supports Username/Password authentication in SOCKS (type 2). All you have to do is to setup the authenticator like this,

    Authenticator.setDefault(new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password.toCharArray());
        }
    });
    

    Again, this may not work for you because it affects all authentication in your JVM (HTTP auth, Proxy Auth).

提交回复
热议问题