0

我正在尝试连接到我的公司数据库,但不断收到身份验证错误。这是尝试访问 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();
4

1 回答 1

0

可能是您的授权标头中缺少空格吗?

httpPost.setHeader("Authorization", "Basic " + encoding);
于 2012-08-07T23:39:53.517 回答