其余模板对json对象给出了400错误的请求

时间:2019-11-05 09:57:56

标签: json resttemplate bad-request

我正在尝试在rest模板put方法中发送json对象,但是它给出了400错误的请求。 但是CURl和邮递员也可以使用同样的方法。 谁能告诉我我在这里做什么?

  HttpHeaders headers = new HttpHeaders();   

  headers.setContentType(MediaType.APPLICATION_JSON);  
 headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));

JSONObject request = new JSONObject();
    request.put("BpId", "100000010");
    request.put("EmailAddress", "sss@test.com");
    request.put("PhoneNumber", "");
    request.put("FaxNumber", "");
    request.put("City", "amsdftfdfdelveen3434");
    request.put("PostalCode", "1344 RC");
    request.put("Street", "sss 123");
    request.put("House_no", "7");
    request.put("Country", "NL");

        HttpEntity<String> requestEntity = new HttpEntity<>(request.toString(), headers);

        ResponseEntity<String> response = restTemplate
                .exchange(sapUrl + "/BP_HEADERSet('{id}')" , HttpMethod.PUT, requestEntity, String.class,id);

0 个答案:

没有答案