Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type ‘application/x-ww

 

This error message  Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported indicates that the server does not support receiving  application/x-www-form-urlencoded data of the type.

If your server-side code is written using the Spring framework, you can try to receive  application/json data of type instead.

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class YourController {

    @PostMapping("/your-endpoint")
    public String handlePostRequest(@RequestBody YourDataClass data) {
        // 处理请求的代码
        // 使用 @RequestBody 注解将请求体的 JSON 数据映射到 YourDataClass 对象
        
        // 返回响应数据
        return "Success";
    }
}

In the above example, YourController it is a Spring controller that uses  @PostMapping annotations to specify the method for processing POST requests.

handlePostRequest The method uses  @RequestBody annotations to map the JSON data of the request body into  YourDataClass an object. You need to create a corresponding class to store the request data according to the actual situation.

Also, make sure you specify the correct  Content-Type as  in your request header application/json, for example:

axios.post(url, jsonData, {
  headers: {
    'Content-Type': 'application/json'
  }
})

 

 

Guess you like

Origin blog.csdn.net/m0_53286358/article/details/131932954