[英]How do I POST/PUT JSON to a REST API endpoint without specifying Content-Type: application/json header
I am working on typical Spring Boot REST API project and I am trying to figure out why all my POST and PUT endpoints API are getting "Unsupported Media Type" error if I don't specify Content-Type: application/json header.(so, if I unchecked Content-Type: application/json header in Postman, I get this error and everything works fine if I check that.)我正在处理典型的 Spring Boot REST API 项目,我试图弄清楚为什么如果我没有指定内容类型,我所有的 POST 和 PUT 端点 API 都会收到“不支持的媒体类型”错误:application/json header。(所以,如果我在 Postman 中取消选中 Content-Type: application/json header,我会得到这个错误,如果我检查它,一切正常。)
Do I need to specify?我需要指定吗? Are there any ways that I can make them work without Content-Type: application/json header?有没有什么方法可以让它们在没有 Content-Type: application/json header 的情况下工作?
Thanks in advance,提前致谢,
You can always use the @RestController
for the controller and use the appropriate method like @GetMapping, @PostMapping to make this work.您始终可以将@RestController
用于 controller,并使用适当的方法(如 @GetMapping、@PostMapping)来完成这项工作。 So, basically spring requires content type because the input could be anything.所以,基本上 spring 需要内容类型,因为输入可以是任何东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.