Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

Why does Apache's HttpClient BasicCredentialsProvider work with digest authentication?

I connect to a server using "Digest Authentication". This example code from Apache lets me connect programmatically using their HttpClient (Java) code. My question is why does this work when it is using a BasicCredentialsProvider()? I figured that was for pages secured through "Basic" authentication. But it seems to work for this page secured through "Digest Authentication".

Their guide does say "Digest" is a supported AuthScheme, but I thought it would require a different type of CredentialsProvider. Why does this code work using the BasicCredentialsProvider?

static void getStuff() throws Exception {
        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(
                new AuthScope( "http://someserver", 80),
                new UsernamePasswordCredentials("username", "password".toCharArray()));
        try (final CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultCredentialsProvider(credsProvider)
                .build()){
            final HttpGet httpget = new HttpGet("http://someserver/somepage");

            System.out.println("Executing request " + httpget.getMethod() + " " + httpget.getUri());
            try (final CloseableHttpResponse response = httpClient.execute(httpget)) {
                System.out.println("-----------------------------------------");
                System.out.println(response.getCode() + " " + response.getReasonPhrase());
                System.out.println(EntityUtils.toString(response.getEntity()));
            }
        }
    }
question from:https://stackoverflow.com/questions/66067570/why-does-apaches-httpclient-basiccredentialsprovider-work-with-digest-authentic

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...