简体   繁体   中英

Jetty HTTP Client Digest Auth

I am trying to get authenticated using a Jetty HTTP Client and Digest Auth.

I always get the Exception:

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

Here is my Code:

    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);

For testing purposes i use a http://httpbin.org/ endpoint, but i also tried other endpoints - all unsuccessfully...

Am i missing something or doing wrong?

I believe this message represents the 401 http status and the situation when you have to pass an Authorization header in the request.

For example this is a typical situation when you're trying access to the OAuth 2.0 secured endpoint without a token. At least this is what I have faced with, having the very same error with jetty http client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM