基本身份验证CODE 401问题

时间:2012-10-21 11:24:23

标签: java authentication authorization basic-authentication

我对Basic Auth有些问题。

服务器返回代码401,我不明白我的代码有什么问题。

我有:

URL url = new URL("https://www.external_site.it/Login.do");

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

    connection.setRequestProperty("Authorization","Basic "+Base64.encodeBase64String((username+":"+password).getBytes()));
    connection.setRequestMethod("GET");
    connection.connect();

System.out.println("\nRESPONSE CODE:\t\t" + connection.getResponseCode());
System.out.println("RESPONSE MESSAGE:\t" + connection.getResponseMessage());

我将base64字符串与标题中的字符串进行了比较,它是相等的。

0 个答案:

没有答案