智慧保安后台管理-外网项目备份
tangzy
2021-07-26 adca98ba944374e7e619beeebe97607f3f33572b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.springblade.common.utils;
 
import com.alibaba.fastjson.JSON;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
 
public class arg {
    public static String url="http://192.168.0.109:80";
    public static String test01(String path,Object obj) throws Exception{
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(path);
        httpPost.setEntity(new StringEntity(JSON.toJSONString(obj),
            ContentType.create("application/json", "UTF-8")));
        CloseableHttpResponse execute = httpClient.execute(httpPost);
        HttpEntity entity = execute.getEntity();
        String str = EntityUtils.toString(entity);
        httpPost.clone();
        httpClient.close();
        System.out.println(str);
        return str;
    }
}