package com.legalPersonMonitor.connections;


import org.apache.http.*;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
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;

import java.io.IOException;

/**
 * Created by zhangdahui on 2017/5/18.
 */
public class HttpClientPool {

    public static String  postRequest(String url, String body) {

        HttpPost httpPost = new HttpPost(url);
        CloseableHttpClient hc = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        StringEntity se = new StringEntity(body, "UTF-8");
        se.setContentType("application/json");
        httpPost.setEntity(se);
        String respStr="";
        try {
            response = hc.execute(httpPost);
            HttpEntity et = response.getEntity();
            respStr = EntityUtils.toString(et);
            return respStr;
        } catch (IOException e) {
            e.printStackTrace();

        } finally {

        }
        return respStr;

    }


}
