Java HTTP Proxy Authentifizierung
11.Februar 2008
HTTP-Proxy-Authentifikation
Ggf. erfordert der HTTP-Proxy eine Authentifikation. Dabei ist für normale JAVA-Web Zugriffe Folgendes notwendig:
URL url = new URL(theUrl);
URLConnection conn = url.openConnection();
String encoded = getBas64EncodeCredentials(getProxyUser(), getProxyPasswd());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encoded);
conn.connect();
Base64 codierte Credentials:
Liefert die Base64 codierten Credentials des Benutzers.
private String getBas64EncodeCredentials(String user, String passwd) {
String userPasswd = user + ":" + passwd;
String encoded = new String(Base64.encode(userPasswd.getBytes()));
return encoded;
}
Entry Filed under: authentication. Schlagworte: http, java, proxy.
Trackback this post | Subscribe to the comments via RSS Feed