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'
  }
})

 

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值