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