I have to access an https site through my java code. But it returns 401 response. I included my code below.
try {
URL u = new URL(url);
HttpURLConnection http = (HttpURLConnection)u.openConnection();
http.setAllowUserInteraction(true);
http.connect();
String userpassword = "HP:M0lveau";
byte[] encoded = Base64.encodeBase64(userpassword.getBytes());
String encodedAuthorization = new String(encoded);
http.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
InputStream is = http.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
return stringBuilder.toString();
} catch (IOException ioe) {
logger.debug("fetchDataFromServer:IOException");
return null;
}
Please help as early as possible.. Thanks in advance....