原来我连接的服务器只提供ntlm身份验证。我使用指南实现了ntlm身份验证
here
. 我修改了问题中列出的代码,使其看起来是这样,并且它起作用:
HttpContext context = null;
if(feedSpec.isAuthenticated()) {
context = new BasicHttpContext();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, new NTCredentials(feedSpec.getHttpUsername(), feedSpec.getHttpPassword(), "", ""));
context.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
}
HttpGet httpGet = new HttpGet(feedSpec.getUri());
HttpResponse httpResponse = httpClient.execute(httpGet, context);