【问题标题】:Authentication fails in HttpClient but OK in browser身份验证在 HttpClient 中失败,但在浏览器中正常
【发布时间】:2010-01-06 16:31:36
【问题描述】:

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

代码(部分):

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 

【问题讨论】:

    标签: java httpclient http-authentication


    【解决方案1】:

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

    【讨论】:

    • 完美!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多