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: , , .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


del.icio.us

Kategoriewolke

authentication Google DATA API