vue项目post请求中携带‘Content-Type‘: ‘application/json;charset=UTF-8‘

24 篇文章 0 订阅
16 篇文章 1 订阅

今天使用post方法向后端请求数据,始终不成功,最后在方法请求头中加上 ‘Content-Type’: ‘application/json;charset=UTF-8’,请求成功

 async bpaParams() {
      const res = await this.$http.post(
        '/acline/datbpagenerate',
        JSON.stringify(data),
        {
          headers: {
            'Content-Type': 'application/json;charset=UTF-8',
          },
        }
      )
      console.log(res)
    },
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用提到了一个错误信息:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported”,这个错误通常出现在使用axios发起请求时,参数格式为x-www-form-urlencoded时。而引用解释了这个错误的原因,即@RequestBody需要的参数格式是JSON类型,而x-www-form-urlencoded是以键值对拼接的形式。解决这个问题的方法有两种: 1. 后端解决:可以在后端对参数进行处理,将x-www-form-urlencoded格式的参数转换为JSON格式。这样@RequestBody就能正常接收参数了。 2. 前端解决:在封装axios时,可以修改参数类型为application/json;charset=UTF-8,即使用JSON格式的参数。可以通过修改axios的默认请求头来实现,例如:instance.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'。 因此,你可以根据具体的情况选择其一种解决方法来解决这个问题。123 #### 引用[.reference_title] - *1* [Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported](https://blog.csdn.net/weixin_40873693/article/details/127036277)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* *3* [SpringBoot +Vue前后端分离项目报错:Content type ‘application/x-www-form-urlencoded;charset=UTF-8...](https://blog.csdn.net/qq_47188967/article/details/129685908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值