简体   繁体   English

如何在不指定内容类型的情况下将 JSON POST/PUT 到 REST API 端点:application/json header

[英]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.

相关问题 JAX-RS:使用 JSON POST 数据而不将 Content-Type 标头设置为 application/json - JAX-RS: Consuming JSON POST data without setting Content-Type header to application/json 如何添加内容类型 header application/json 以取消映射后端点? - How to add content-type header application/json to void postmapping endpoint? 使用Content-Type:application / json时,对Activiti REST API的POST请求导致CORS问题 - POST request to Activiti REST API causes CORS issue when using Content-Type:application/json 我如何设置 Content-Type 以响应 application/json - How I can set Content-Type in react to application/json 使用 Fetch API javascript 将 Content-Type 设置为 application/Json - set Content-Type to application/Json using Fetch API javascript 如何发送请求标题是“内容类型”:“应用程序/ json”在排球时获取 - How to send request Header is “Content-Type”:“application/json” when GET on Volley 没有为Content-Type定义解析器:application / json - No parser defined for Content-Type: application/json 在 Spring 中读取 Content-Type 应用程序/json - Reading Content-Type application/json in Spring GET调用REST API,Accept为text / csv,content-Type为application / json。 应答的形式应该是什么? - GET call on REST API with Accept as text/csv and content-Type as application/json. In what format should the reponse be? 错误:使用'application / json'Content-Type和带有json数据的原始POST - error : use 'application/json' Content-Type and raw POST with json data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM