更多,参看:案例,下面代码是我根据案例编写的一个请求:
public static String postObject(){
RestTemplate restTemplate = new RestTemplate();
String url = "http://222.222.222.222:222/dcmp/ws/manuInfo";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
JSONObject rspObj = new JSONObject();
rspObj.put("creditcode_nbr", "913100001331360409G");
rspObj.put("dataupdate_nbr", "12345678");
rspObj.put("warehousearea_nbr", "913100001331360409G.01");
rspObj.put("start_date", "20200401");
ArrayList<Map> inventoryInfo_list = new ArrayList<>();
Map inventoryInfo_list_item = new HashMap();
inventoryInfo_list_item.put("whpname_nbr","1049");
inventoryInfo_list_item.put("number","2");
inventoryInfo_list_item.put("unit","K");
inventoryInfo_list.add(inventoryInfo_list_item);
rspObj.put("inventoryInfo_list", inventoryInfo_list);
HttpEntity<JSONObject> request = new HttpEntity<>(rspObj, headers);
ResponseEntity<String> response = restTemplate.postForEntity( url, request , String.class );
return response.getBody();
}
网友评论