直接上代码:
public class HttpUtils {
private static final RestTemplate restTemplate = new RestTemplate();
// Get请求
public static String Get(String url, Map params) {
String uri = buildUri(url, params);
ResponseEntity response = restTemplate.getForEntity(uri, String.class);
return response.getBody();
}
// Get请求
public static String Get(String uri) {
ResponseEntity response = restTemplate.getForEntity(uri, String.class);
return response.getBody();
}
// Post请求(JSON请求)
public static String JPost(String url, Map params) {
HttpEntity