Resttemplate submitted online are many ways to use the time when constructing HttpEntity objects, or use the following method
1 String jsonData = JSON.toJSONString(vo); 2 HttpHeaders headers = new HttpHeaders(); 3 headers.setContentType(MediaType.APPLICATION_JSON); 4 HttpEntity<String> request = new HttpEntity<>(jsonData, headers);
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, request, JSONObject.class);
This method appears in the body json body inside
Another embodiment of the method filed formdata construct a map as follows:
MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.add("method", UPLOAD_METHOD); map.add("timestamp", timestamp + ""); map.add("sign", SIGN); map.add("companyNo", companyNo); HttpHeaders headers = new HttpHeaders(); HttpEntity<String> request = new HttpEntity<>(map , headers); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, request, JSONObject.class);
In fact, in three post submission stuff in it
header
query
body
The springboot in fromdata is (other frameworks uncertain) may be submitted as part of the query
as follows
MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.add("method", UPLOAD_METHOD); map.add("timestamp", timestamp + ""); map.add("sign", SIGN); map.add("companyNo", companyNo); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> request = new HttpEntity<>(jsonData, headers); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiURL).queryParams(map); ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(builder.toUriString(), request, JSONObject.class);
The map constructed using UriComponentsBuilder inside url