尝试使用org.springframework.web.client.RestTemplate
类进行POST调用时出现以下错误:
"400 null","stackTrace":"org.springframework.web.client.HttpClientErrorException: 400 null
下面是我的代码:
public void PostInsertOrUpdateDisplayCounts(CountsDataResults countsDataResults, String displayId) {
String postUrl = "http://zld05300.vci.com:38767/application/display/C9B367BE340288EFE7D835FD587F2A3/counts";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<CountsDataResults> countsDataResultsEntity = new HttpEntity<CountsDataResults>(countsDataResults, headers);
//execute the post call:
ResponseEntity<Response> reponseEntity = restTemplate.exchange(postUrl, HttpMethod.POST, countsDataResultsEntity, Response.class);
}
以下是将接收请求的服务器代码:
@POST
@Path("/application/display/{displayId}/counts")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response insertOrUpdateDisplayCounts(@RequestBody CountsDataResults countsList,@PathParam("displayId")String displayId);
下面是insertOrUpdateDisplayCounts
方法的实现:
@Override
public Response insertOrUpdateDisplayCounts(CountsDataResults countsList, String displayId) {
String result = countsAPI.insertOrUpdateDisplayCountTables(countsList, displayId);
if(result == "success")
return Response.created(null).build();
else
return Response.status(Status.FORBIDDEN).build();
}
我很肯定参数参数为非null,并且我已经成功地使用邮递员对端点进行了相同的POST调用测试,并收到了期望的响应-为什么我会收到此异常?