|
@ -1,5 +1,6 @@
|
|
|
package com.yihu.jw.util.http;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import org.apache.http.Consts;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.NameValuePair;
|
|
@ -14,8 +15,10 @@ import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.io.*;
|
|
@ -485,4 +488,33 @@ public class HttpClientUtil {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 爱牵挂请求
|
|
|
* @param url
|
|
|
* @param params
|
|
|
* @return
|
|
|
*/
|
|
|
public org.springframework.http.HttpEntity<JSONObject> cookiePostHttp(String url,MultiValueMap<String, String> params){
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
MediaType type = MediaType.parseMediaType("application/x-www-form-urlencoded");
|
|
|
headers.setContentType(type);
|
|
|
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
org.springframework.http.HttpEntity<MultiValueMap<String, String>> request = new org.springframework.http.HttpEntity<>(params, headers);
|
|
|
org.springframework.http.HttpEntity<JSONObject> response = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
// public static void main(String[] args) {
|
|
|
// JSONObject param = new JSONObject();
|
|
|
// param.put("username","13559485270");
|
|
|
// param.put("password","zjxl@2021");
|
|
|
// MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
|
|
// map.add("username","13559485270");
|
|
|
// map.add("password","zjxl@2021");
|
|
|
// org.springframework.http.HttpEntity<JSONObject> response = cookiePostHttp("http://api.aiqiangua.com:8888/api/auth/login",map);
|
|
|
// org.springframework.http.HttpHeaders responseHeaders = response.getHeaders();
|
|
|
// System.out.println("11111");
|
|
|
// }
|
|
|
}
|