Jetty HTTP客户端摘要验证

时间:2017-05-13 13:17:31

标签: java jetty

我正在尝试使用Jetty HTTP Client和Digest Auth进行身份验证。

我总是得到例外:

org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header

这是我的代码:

    HttpClient httpClient = new HttpClient();

    httpClient.start();

    String realm = "me@kennethreitz.com";
    String user = "user";
    String pass = "passwd";
    URI uri =new URI("http://httpbin.org/digest-auth/auth/user/passwd/MD5");
    AuthenticationStore a = httpClient.getAuthenticationStore();
    a.addAuthentication(
        new DigestAuthentication(uri, realm, user, pass));

    ContentResponse response = httpClient
            .newRequest(uri)
            .send();
            //.get(5, TimeUnit.SECONDS);

    System.out.println(response);

出于测试目的,我使用http://httpbin.org/端点,但我也尝试了其他端点 - 所有这些都没有成功......

我错过了什么或做错了吗?

1 个答案:

答案 0 :(得分:0)

我认为此消息代表401 http状态以及当您必须在请求中传递Authorization标头时的情况。

例如,当您尝试访问不带令牌的OAuth 2.0安全端点时,这是一种典型情况。至少这是我所面临的问题,而码头http客户端也有同样的错误。

相关问题