授权错误

时间:2012-08-07 23:29:34

标签: android api http authentication post

我正在尝试连接到我的公司数据库但继续收到身份验证错误。这是试图访问api所在网站的代码。这些api与数据库连接。

DefaultHttpClient httpClient = new DefaultHttpClient();
        URL url1 = new URL ("http://www.xxxxxxx.com/");
        String encoding = new   String(org.apache.commons.codec.binary.Base64.encodeBase64
                (org.apache.commons.codec.binary.StringUtils.getBytesUtf8("xx:xxxxxx"))
                );
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader("Authorization", "Basic" + encoding);           
        httpPost.setEntity(new UrlEncodedFormEntity(params)); 
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

1 个答案:

答案 0 :(得分:0)

您的Authorization标头中是否缺少空格?

httpPost.setHeader("Authorization", "Basic " + encoding);