1
我使用HttpURLConnection
类来管理我的Android应用程序中的HTTP连接。问题是,在某些服务器上,我有一个代码使用在互联网浏览器上工作的URL。我使用基本身份验证初始化连接,但我认为这些服务器需要其他模式。我知道它的工作原理与的libcurl和下面的指令:HttpURLConnection身份验证模式
curl_easy_setopt(pCurlHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
但有一个办法做这样的事情在Android?目前,我这样做:
...
connection.setRequestProperty("Authorization", "Basic " + Base64.encode("username:password"));
...
我Authenticator
尝试过:
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("username", "password".toCharArray());
}
});
但我仍然有我的应用程序401。任何想法?