HttpClient Processing Digest Certification

Source: Internet
Author: User

Although the security of Digest authentication is much higher than that of basic authentication, from the interface call, it is not more complex than the basic authentication, and the realm and scheme parameters can be null, this is the same as the Basic authentication call method.


import java.net.uri;import org.apache.http.auth.authscope;import  Org.apache.http.auth.usernamepasswordcredentials;import org.apache.http.client.credentialsprovider;import  org.apache.http.client.methods.CloseableHttpResponse;import  Org.apache.http.client.methods.httpurirequest;import org.apache.http.client.methods.requestbuilder;import  org.apache.http.impl.client.BasicCredentialsProvider;import  Org.apache.http.impl.client.closeablehttpclient;import org.apache.http.impl.client.httpclients;import  org.apache.http.util.entityutils;public class digesttest {    public  static void main (String[] args)  throws Exception {         credentialsprovider credsprovider = new basiccredentialsprovider () ;         credsprovider.setcredentials (New AuthScope ("10.0.0.90",  8080,&nbSP; " Favourite digest realm ",  authscope.any_scheme),                 new usernamepasswordcredentials ("admin",  "password") );        closeablehttpclient httpclient =  Httpclients.custom (). Setdefaultcredentialsprovider (Credsprovider). Build ();         httpurirequest login = requestbuilder.post ()                  .seturi (New uri ("http://10.0.0.100:8080/ Hibaby/getbabiesbygender "))                  .addparameter ("AppKey",  "best")                  .addparameter ("Gender",  "boy"). Build ();         closeableHttpresponse response = httpclient.execute (login);         SYSTEM.OUT.PRINTLN ("Response Status:"  + response.getstatusline ());         string result = entityutils.tostring (response.getentity (),  "UTF-8");         system.out.println ("result: "  + result);     }}


This article is from the "This person's IT World" blog, be sure to keep this source http://favccxx.blog.51cto.com/2890523/1880025

HttpClient Processing Digest Certification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.