【问题标题】:PUT request from Postman is not being received by Java ControllerJava 控制器未收到来自 Postman 的 PUT 请求
【发布时间】: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 中执行。

如果有任何其他信息,请告诉我。是必需的。

【问题讨论】:

    标签: rest postman put


    【解决方案1】:

    我找到了答案。

    实际上,我需要将 Body 中的参数作为原始表单而不是 Postman 中的表单数据传递。

    现在可以了。

    【讨论】:

      猜你喜欢
      • 2020-11-09
      • 2018-02-28
      • 2019-10-20
      • 2016-06-07
      • 2019-07-14
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      相关资源
      最近更新 更多