【发布时间】:2020-09-15 08:29:51
【问题描述】:
我在控制器中编写了多个 REST 端点 [GET、POST 和 PUT]。
GET 和 POST 调用工作正常。但是当我尝试从 Postman 发出 PUT 请求时,我的 java 控制器无法接收该请求。没有错误信息。响应正文为空。 Postman 中的响应码是 200,OK。
这是我的 PUT 端点,它无法从 Postman 获取请求:
@PutMapping(value = "/devRegistration")
public Object deviceRegistration(HttpServletRequest httpRequest,
@RequestBody(required = false) Map<String, Object> jsonBody ){
ResponseEntity<Object> response = null;
System.out.println("jsonBody = "+jsonBody);
devService.deviceRegistration(httpRequest, jsonBody);
return response;
}
这是我的 GET 端点,它工作正常:
@GetMapping(value = "/checkRegistration")
public void checkRegistration(HttpServletRequest httpRequest,
@RequestParam("appId") String appId, @RequestParam("offset") String offset ){
Map<String, Object> jsonBody = new HashMap<String, Object>();
jsonBody.put("appId", appId);
jsonBody.put("offset", offset);
service.checkRegistration(httpRequest, jsonBody);
}
PUT 请求的带有标题和正文的邮递员 URL 是:
https://localhost:8443/api/device/devRegistration
In Body:
app_Id : some value
offset : some value
Headers are:
RequestHeader
Content-Type
Authorization
MobileHeader
SessionToken
但是,System.out.println() 没有在 PUT Endpoint 中执行。
如果有任何其他信息,请告诉我。是必需的。
【问题讨论】: