2009-11-30 59 views
1

我需要一個支持經過身份驗證的socks代理的Java套接字客戶端類,java.net.Proxy只支持整個JVM的一組憑據。我有多個代理,每個都有不同的登錄名。 這裏是java的代理Authenticator所做的,只有一個登錄用於整個JVM。我如何擁有多個?java套接字和代理身份驗證

 
Authenticator.setDefault(new Authenticator(){ 
    protected PasswordAuthentication getPasswordAuthentication(){ 
    PasswordAuthentication p=new PasswordAuthentication("xxx", "xxx".toCharArray()); 
    return p; 
    } 
}); 

回答

3

在你Authenticator實現你可以要求代理認證是使用:getRequestingHost()

根據getRequestingHost()的值,您可以返回該代理的PasswordAuthentication