我遇到一個奇怪的問題,下面的方法。RestTemplate.exchange()DELETE刪除請求正文
@Override
public String deleteToEe(String body) {
logger.debug("Request body");
logger.debug(body);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
headers.add("partner", "test");
headers.add("api_key", "certxxxx");
HttpEntity<String> request = new HttpEntity<String>(body, headers);
ResponseEntity<String> result = null;
try {
result = restTemplate.exchange(targetUrl, HttpMethod.DELETE, request, String.class);
} catch (RestClientException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result.getBody();
}
當我觸發通過Postman的控制器請求映射觸發此方法時,它的工作原理。但是,當測試者通過他們的集成測試觸發此方法,或者當我觸發此方法使用curl
curl -X DELETE -H "Accept: application/json" -H "Content-type: application/json" -d "{"userName": "21", "courseId": "104882_bfaculty3_1024", "isbn": "9780323055", "schoolUserId": "1234" }" http://localhost:8080//api/provision
我得到在這一點上一個空指針異常代碼
result = restTemplate.exchange(targetUrl, HttpMethod.DELETE, request, String.class);
我breakpointed的代碼,看起來像我們有一個請求主體,但由於某種原因,它被放在restTemplate.exchange()調用中。任何人之前看過類似的東西?
被丟棄的是去deleteToEe身體方法還是存在於所有情況下(CURL,控制器...)? – d1x
在DELETE方法中傳遞請求正文是從版本3.0.5開始的支持https://jira.spring.io/browse/SPR-7867 – Arashsoft