我想在内容类型为空时处理 POST 请求。
- 当我添加 consumes = MediaType.APPLICATION_JSON_VALUE 并在邮递员中使用 Content-type 空白发出请求时,我收到以下错误
{
"timestamp": 1581594986909,
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type '' not supported",
"path": "/test"
}
这是代码
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity create(@RequestBody TestRequest testRequest) throws TestException {
LOG.debug("Starting...");
//code
return createtest(testRequest);
}
- 当我删除 consumes = MediaType.APPLICATION_JSON_VALUE 并使用 content-type = blank 发出请求时,我收到以下错误
{
"timestamp": 1581595348209,
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/octet-stream' not supported",
"path": "/test"
}
这是代码
@PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity create(@RequestBody TestRequest testRequest) throws TestException {
LOG.debug("Starting...");
//code
return createtest(testRequest);
}
我想处理这种情况并假设 content-Type= application/json 被发送
