小编Sou*_*jee的帖子

如何使用Spring Boot修复REST Web服务中的POST请求期间的“ HTTP-415”错误

我是Spring Boot的初学者,正在学习自己的方法。

在使用Spring Boot的REST Web服务中进行POST请求期间,如何解决“ HTTP-415”错误,如下所示?我已经尝试过@RequestMapping注解@RequestParam@RequestParam给出其他错误401。但是,415与@RequestMapping和一致@PostMapping

与发出@PostMapping请求。

{
    "timestamp": "2018-12-31T18:29:36.727+0000",
    "status": 415,
    "error": "Unsupported Media Type",
    "message": "Content type 'text/plain;charset=UTF-8' not supported",
    "trace": "org.springframework.web.HttpMediaTypeNotSupportedException: Content type 
    'text/plain;charset=UTF-8' not supported\r\n\tat 
    org.springframework.web.servlet.mvc.method.annotation.
    AbstractMessageConverterMethodArgumentResolver.
    readWithMessageConverters
    (AbstractMessageConverterMethodArgumentResolver.java:224)\r\n\tat 
     org.springframework.web.servlet.mvc.method.annotation.
     RequestResponseBodyMethodProcessor.
     readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
     \r\n\tat org.springframework.web.servlet.mvc.method.
     annotation.RequestResponseBodyMethodProcessor.
     resolveArgument(RequestResponseBodyMethodProcessor.java:130)
     \r\n\tat...................
Run Code Online (Sandbox Code Playgroud)

在提出以下要求时:

发布请求

StudentController.java

@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    :
    :

    @PostMapping("/students/{studentId}/courses")
    public ResponseEntity<Void> registerStudentForCourse(
            @PathVariable String studentId,
            @RequestBody Course newCourse) {
        Course course = …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc http-status-code-415 spring-boot

1
推荐指数
2
解决办法
2537
查看次数