私はSpring RestTemplateを使用してSpringのRestTemplateを使用したHTTP DELETE要求をExchangeメソッドで実行しようとしていますが、常にthis questionのような400のBad Requestを取得します。 JavaScriptやその他のツールを使用すると、このAPI呼び出しをDELETEで呼び出すことができます。 私はJavaを知っています< 1.8 doesentは本体でDELETEをサポートしていますが、1.8では可能です。see here。私はspring-web-4.2.6を使用しています.jdk 1.8でリリースしますので、方法が必要であると思います。Spring RestTemplateはbody jdkとDELETEを交換します。012
マイコード:
public DealResponse closePosition(DealCloseRequest dealCloseRequest) {
try {
ObjectMapper mapper = new ObjectMapper();
//Object to JSON in String
String jsonInString = mapper.writeValueAsString(dealCloseRequest);
HttpEntity<String> entity = new HttpEntity<String>(jsonInString, this.headers);
//execute request
ResponseEntity<DealResponse> response = restTemplate.exchange("https://" + this.domain + "/gateway/deal/positions/otc", HttpMethod.DELETE, entity, DealResponse.class);
//return filled DealResponse object
return response.getBody();
} catch (JsonProcessingException e) {
this.logger.warn("could not close Position because: "+e);
return null;
}
}
エラーメッセージ:
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
誰もが春のrestTemplateでこれを行う方法を知っていますか?