Java Tip: Basic Authentication with HttpURLConnection

Java Tip: Basic Authentication with HttpURLConnection

Note: This article will be emailed to your friend.

Java provides a super simple, yet hidden from plain view, way to do basic authentication of HttpURLConnection / URLConnection.

Before making a connection add the following lines of code:

final String login =”…”;
final String password =”…”;

Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (login, password.toCharArray());
[...]

Read the rest of this article (146 words)

Please fill in the following fields

* - Required

Your Name: *

Your E-Mail: *

Your Remarks:

Friend's Name: *

Friend's E-Mail: *

Protected by Comment Guard Pro