如何连接到具有android所需身份验证的http?

时间:2014-09-11 08:08:06

标签: android http httpurlconnection

我在使用android中需要的身份验证访问http时遇到问题。我已经像下面的代码一样尝试了HttpUrlConnection:但是我仍然得到错误401 UNAUTHORIZED

        String encoded = Base64.encodeToString((_username+":"+_password).getBytes(),Base64.NO_WRAP); 
        connection.setRequestProperty("Authorization", "Basic "+encoded);
        connection.setRequestProperty("Connection", "Keep-Alive");
        connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
        connection.setRequestProperty("Host", "crmweb.com.ph");
        connection.setRequestProperty("Cookie", "");
        connection.connect();

这是我想要放在android中的代码的图像:enter image description here

感谢您的帮助。

0 个答案:

没有答案