我嘗試從我的數據庫的電子商務網站發送發貨狀態,但我得到:400錯誤的請求爲POST
400錯誤的請求錯誤。
有沒有人有任何想法?
HashMap orderItems = new HashMap<String, String>();
orderItems.put("id","558443685");
ArrayList<HashMap<String,String>> orderItemsArray = new ArrayList<HashMap<String,String>>();
orderItemsArray.add(orderItems);
HashMap contentOrderFulfillment = new HashMap<String, Object>();
contentOrderFulfillment.put("tracking_number", null);
contentOrderFulfillment.put("line_items",orderItemsArray);
HashMap orderFulfillment = new HashMap<String, Object>();
orderFulfillment.put("fulfillment", contentOrderFulfillment);
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
HttpHeaders headers = new HttpHeaders();
headers.add("X-ABC-Access-Token", "9a4d5c56a7edf1ac5bb17aa1c");
headers.add("Content-Type", MediaType.APPLICATION_JSON.toString());
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<String, Object>();
requestBody.add("fulfillment", orderFulfillment);
HttpEntity formEntity = new HttpEntity<MultiValueMap<String, Object>>(requestBody, headers);
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<String> responseEntity = restTemplate.exchange("https://mysite.abc.com/admin/orders/406287121/fulfillments.json",HttpMethod.POST, formEntity,String.class);
System.out.println("Response="+responseEntity.getBody());