xiejun
2023-08-14 885baab441cf03e1d3ea02400f9eee9aa530c7fa
Source/UBCS/ubcs-codeApply/src/main/java/com/vci/ubcs/codeapply/utils/HttpUtil.java
@@ -4,6 +4,7 @@
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.vci.ubcs.code.vo.webserviceModel.apply.InterParameterVO;
import com.vci.ubcs.codeapply.object.R;
import com.vci.ubcs.codeapply.object.TokenUserObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.http.*;
import org.apache.http.client.ClientProtocolException;
@@ -17,9 +18,12 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.formula.functions.T;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -260,7 +264,7 @@
      HttpEntity entity1 = response.getEntity();
      String result = null;
      try {
         result = EntityUtils.toString(entity, "UTF-8");
         result = EntityUtils.toString(entity1, "UTF-8");
         // 使用Apache提供的工具类进行转换成字符串
         if(StringUtils.isNotBlank(result)){
            r = JSONObject.toJavaObject(JSONObject.parseObject(result), R.class);
@@ -307,7 +311,49 @@
      }
      return result;
   }
   /**
    * 发送HttpPost请求,参数为map
    * @param url
    * @param dataMap
    * @return
    */
   public static String sendFormPost(String url, Map<String,String> dataMap, Map<String,String> headers) {
      String result = null;
      try {
         //json 格式
         List<NameValuePair> nvps = new ArrayList<>();
//
         HttpPost httppost = new HttpPost(url);
         if (dataMap != null && dataMap.size() > 0) {
            for (Map.Entry<String, String> entry : dataMap.entrySet()) {
               nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
            }
         }
         /*
          * 添加请求头信息
          */
         if (headers != null && headers.size() > 0) {
            for (Map.Entry<String, String> entry : headers.entrySet()) {
               httppost.addHeader(entry.getKey(), entry.getValue());
            }
         }
         httppost.setEntity(new UrlEncodedFormEntity(nvps, "utf-8")); //将参数传入post方法中
         //httppost.setEntity(entity);
         CloseableHttpResponse response = null;
         response = httpclient.execute(httppost);
         HttpEntity entity1 = response.getEntity();
         result = EntityUtils.toString(entity1, "UTF-8");
         // 使用Apache提供的工具类进行转换成字符串
         if (StringUtils.isNotBlank(result)) {
            return result;
         }
      }catch (Throwable e){
         e.printStackTrace();;
      }
      return result;
   }
   /**
    * 发送不带参数的HttpPost请求
    * @param url