首页 > 解决方案 > 邮递员“状态”:415,“错误”:“不支持的媒体类型”,

问题描述

我试图创建一个类,我可以在其中将客户(客户)添加到类(aula)

@RequestMapping(value = "/aulas/{numero}/{numerocliente}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_XML_VALUE, produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity<Object> addClienteAula(@PathVariable("numero") int nraula, @PathVariable("numerocliente") int nrclente) {
    try {
        AulaService.addAlunoAula(nraula, nrclente);
        return new ResponseEntity<>(HttpStatus.CREATED);
    } catch (Exception e) {
        return new ResponseEntity<>(new ErroDTO(e), HttpStatus.CONFLICT);
    }

}

这是我对邮递员的要求:
http://localhost:8080/api/aulas/1/23

结果是这样的:

{
    "timestamp": "2020-04-25T00:12:02.300+0000",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "Content type 'text/plain' not supported",
    "path": "/api/aulas/1/23"
}

标签: javawebserverpostman

解决方案


在邮递员的请求标头中提及您的内容类型

Content-Type application/xml

推荐阅读