#java代码进行http请求(org.springframework.http
)
public static void main(String[] args) {
// 请求路径
String url = "";
RestTemplate restTemplate = new RestTemplate();
// 消息头
HttpHeaders headers = new HttpHeaders();
headers.add("accept", "*/*");
headers.add("connection", "keep-alive");
headers.add("User-Agent", "Mozilla/5.0 ");
// cookie or token可以携带
headers.add("Cookie", "user_locale = zh - CN;");
// 参数
JSONObject body = new JSONObject();
String id = "";
body.put("code", id);
body.put("channel", "PC");
HttpEntity<String> httpEntity = new HttpEntity(body, headers);
// 进行请求并且返回
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, httpEntity, JSONObject.class);
}