String url = "https://www.baidu.com";
HttpHeaders headers = new HttpHeaders();
//设置请求头,自己从浏览器复制一个,如果请求的网站没要求也可以不设置
headers.set("user-agent", "...");
//添加参数
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add("keyword","test");
//...
//装填
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(params, headers);
exchange = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
String res = exchange.getBody();
标签:Java,String,exchange,RestTemplate,headers,params,new,Post,请求
From: https://www.cnblogs.com/eaglex3/p/16799775.html