HttpClient中的身份验证失败,但浏览器中的确认无效

时间:2010-01-06 16:31:36

标签: java httpclient http-authentication

我正在使用HttpClient 4.0从远程主机获取一些XML。当我使用诸如https://user:pwd@www.somesite.com之类的URL时,它在浏览器中工作正常但在具有此堆栈跟踪的HttpClient中失败(如下)。有什么建议?我在设置SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER以处理HTTPS请求时使用ThreadSafeClientConnManager

代码(部分):

final HttpGet get= new HttpGet(url);
final HttpResponse response = this.client.execute(get);
return new BasicResponseHandler().handleResponse(response);

堆栈跟踪:

01-05 22:34:03.783: ERROR/SearchResults(11565): 
    Failed to process request to URL: 
    https://user:pwd@www.somesite.com/products/foo/meta/xml_proper_encoding.jsp?version=1
01-05 22:34:03.783: ERROR/SearchResults(11565): 
    org.apache.http.client.HttpResponseException: Unauthorized 

1 个答案:

答案 0 :(得分:4)

this example中传递UsernamePasswordCredentials,而不是在网址中传递。