| | |
| | | package com.panzhihua.common.utlis; |
| | | |
| | | import java.io.*; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.panzhihua.common.constants.HttpConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.http.Header; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.io.*; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import com.panzhihua.common.constants.HttpConstant; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @program: springcloud_k8s_panzhihuazhihuishequ |
| | |
| | | public class HttpClientUtil { |
| | | /** |
| | | * 通过post方式调用http接口 |
| | | * @param url url路径 |
| | | * @param jsonParam json格式的参数 |
| | | * @param reSend 重发次数 |
| | | * @param headerKey header键值 |
| | | * @param headerValue headervalue |
| | | * |
| | | * @param url |
| | | * url路径 |
| | | * @param jsonParam |
| | | * json格式的参数 |
| | | * @param reSend |
| | | * 重发次数 |
| | | * @param headerKey |
| | | * header键值 |
| | | * @param headerValue |
| | | * headervalue |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static String sendPostByJson(String url, String jsonParam,int reSend,String headerKey,String headerValue) { |
| | | public static String sendPostByJson(String url, String jsonParam, int reSend, String headerKey, |
| | | String headerValue) { |
| | | //声明返回结果 |
| | | String result = ""; |
| | | //开始请求API接口时间 |
| | |
| | | |
| | | /** |
| | | * 使用http请求调用接口,参数类型为xml |
| | | * @param urlStr 请求地址 |
| | | * @param data 请求参数 |
| | | * |
| | | * @param urlStr |
| | | * 请求地址 |
| | | * @param data |
| | | * 请求参数 |
| | | * @return 调用结果 |
| | | */ |
| | | public static String httpsRequest(String urlStr,String data) { |
| | |
| | | con.setRequestProperty("Cache-Control", "no-cache"); |
| | | con.setRequestProperty("Content-Type", "text/xml"); |
| | | |
| | | OutputStreamWriter out = new OutputStreamWriter(con |
| | | .getOutputStream()); |
| | | OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream()); |
| | | log.info("urlStr=" + urlStr); |
| | | log.info("xmlInfo=" + data); |
| | | out.write(new String(data.getBytes("UTF-8"))); |
| | | out.flush(); |
| | | out.close(); |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(con |
| | | .getInputStream())); |
| | | BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); |
| | | String line = ""; |
| | | StringBuffer sb = new StringBuffer(); |
| | | for (line = br.readLine(); line != null; line = br.readLine()) { |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * http请求工具类,get请求 |
| | |
| | | /** |
| | | * http请求工具类,post请求 |
| | | * |
| | | * @param url url |
| | | * @param param 参数值 仅支持String |
| | | * @param url |
| | | * url |
| | | * @param param |
| | | * 参数值 仅支持String |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | |
| | | |
| | | /** |
| | | * get请求 |
| | | * @param url 请求地址(get请求时参数自己组装到url上) |
| | | * @param headerMap 请求头 |
| | | * |
| | | * @param url |
| | | * 请求地址(get请求时参数自己组装到url上) |
| | | * @param headerMap |
| | | * 请求头 |
| | | * @return 响应文本 |
| | | */ |
| | | public static String get(String url, Map<String, String> headerMap,String param) { |