第一种是formdata形式,在header参数里可以直接看到
代码demo如下:
url=‘http://posturl‘;JSONObject postData = new JSONObject();
postData.put("shopid", 1);
JSONObject json = restTemplate.postForEntity(url, postData, JSONObject.class).getBody();
使用RestTemplate发送multipart/form-data格式的数据
String url = ‘http://posturl‘;
MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("shopid","1");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
return restTemplate.postForEntity(url, request,String.class);
对header进行请求头设置,如果不设置也可以直接post那么就是如下的
String url = ‘http://posturl‘; MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>(); map.add("shopid","1");
return restTemplate.postForEntity(url, map,String.class);
原文:https://www.cnblogs.com/xinweiyun/p/9348273.html