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

这个错误提示 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 表明服务器不支持接收 application/x-www-form-urlencoded 类型的数据。

如果你的服务器端代码是使用Spring框架编写的,你可以尝试改为接收 application/json 类型的数据。

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";
    }
}

在上面的示例中,YourController 是一个Spring控制器,使用 @PostMapping 注解指定了处理POST请求的方法。

handlePostRequest 方法使用 @RequestBody 注解将请求体的 JSON 数据映射到 YourDataClass 对象中。你需要根据实际情况创建一个对应的类来存储请求数据。

另外,请确保你的请求头中指定了正确的 Content-Type 为 application/json,例如:

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

 

猜你喜欢

转载自blog.csdn.net/m0_53286358/article/details/131932954
今日推荐