123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package fi.rim.utils;
- import com.alibaba.fastjson.JSON;
- import kd.bos.script.annotations.KSObject;
- import org.apache.http.HttpEntity;
- 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.HttpClientBuilder;
- import org.apache.http.util.EntityUtils;
- @KSObject
- public class ApiHttpUtils {
- public static String Posthttp(String url, String Params) throws Exception {
-
- CloseableHttpClient httpClient = HttpClientBuilder.create().build();
-
-
- HttpPost httpPost = new HttpPost(url);
- httpPost.setHeader("Content-type", "application/json;charset=utf-8");
- StringEntity entity = new StringEntity(Params,"UTF-8");
-
-
- entity.setContentEncoding("UTF-8");
-
- entity.setContentType("application/json");
- httpPost.setEntity(entity);
-
- CloseableHttpResponse response = httpClient.execute(httpPost);
-
- HttpEntity responseEntity = response.getEntity();
- com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
- if (responseEntity != null) {
- jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
- return jsonObject.toJSONString();
- }
-
- if (httpClient != null) {
- httpClient.close();
- }
- if (response != null) {
- response.close();
- }
- return "";
- }
- }
|