开发者

java socket and Proxy authentication

开发者 https://www.devze.com 2022-12-13 07:13 出处:网络
I need a Java Socket client class that supports authenticated socks proxy, java.net.Proxy only supports one set of credentials for the whole JVM.I have multiple proxies each with different logins.

I need a Java Socket client class that supports authenticated socks proxy, java.net.Proxy only supports one set of credentials for the whole JVM. I have multiple proxies each with different logins. here's what java's proxy Authenticator does, only one login for the whole JVM. how do I have multiple?

Authenticator.setDefault(new Authenticator(){
  protected  PasswordAuthentication  getPasswordAuthentication(){
   PasswordAuthentication p=new PasswordAuthentication("xxx", "xxx".toCharAr开发者_如何学JAVAray());
   return p;
  }
 });


In your Authenticator implementation you can ask for the proxy the authentication is for using: getRequestingHost().

Based on the value of getRequestingHost() you can return the PasswordAuthentication for that proxy.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号