本人写的Digest 认证一次通过,不需要按照常规的方式来
public void postMethod(String url, String query) {
try {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope("192.168.1.105", 9000),//请求地址 + 端口号
new UsernamePasswordCredentials("admin", "admin"));// 用户名 + 密码 (用于验证)
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
HttpPost postMethod = new HttpPost(url);//请求详细地址(如:http://192.168.1.105:9000/MotorVehicles)
StringEntity s = new StringEntity(query);//向后台传的json数据
s.setContentEncoding("utf-8");//编码
s.setContentType("application/json");//发送json数据需要设置contentType
postMethod.setEntity(s);
HttpResponse response = httpclient.execu