8 anni fa
parent
commit
d401f048ce

+ 2 - 20
patient-co-wlyy/src/main/java/com/yihu/wlyy/util/HttpClientUtil.java

@ -2,12 +2,8 @@ package com.yihu.wlyy.util;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.ParseException;
@ -16,12 +12,9 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
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.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.web.client.RestTemplate;
public class HttpClientUtil {
@ -37,21 +30,10 @@ public class HttpClientUtil {
		CloseableHttpClient httpclient = HttpClients.createDefault();
		// 创建httppost
		HttpPost httppost = new HttpPost(url);
		StringEntity uefEntity;
		UrlEncodedFormEntity uefEntity;
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			Map<String, Object> temp = new HashMap<>();
			Iterator<NameValuePair> it = params.iterator();
			while (it.hasNext()){
				NameValuePair nvp = it.next();
				temp.put(nvp.getName(), nvp.getValue());
			}
			String json = objectMapper.writeValueAsString(temp);
			uefEntity = new StringEntity(json, chatSet);
			uefEntity = new UrlEncodedFormEntity(params, chatSet);
			httppost.setEntity(uefEntity);
			httppost.addHeader(HTTP.CONTENT_TYPE, "application/json");
			CloseableHttpResponse response = httpclient.execute(httppost);
			try {
				HttpEntity entity = response.getEntity();