项目接口返回
code: 500
data: null
message: “Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported”

原因在于,接口不支持application/x-www-form-urlencoded;charset=UTF-8

通过看swagger的接口传递数据类型来修改,
将axios的请求头配置为

headers: {'X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/json; charset=UTF-8'}


request.js

import axios from 'axios'
import qs from 'qs'
import router from '../../router'
axios.defaults.timeout = 65000;
window.axiosCancel = [] ; // 全局定义一个存放取消请求的标识
axios.interceptors.request.use(config => {config.cancelToken = new axios.CancelToken(cancel => {window.axiosCancel.push({cancel})})// loadingreturn config// 添加取消标记}, error => {return Promise.reject(error)
})
axios.interceptors.response.use(response => {return response
},
error => {return Promise.resolve(error.response)
})
export function checkStatus(response) {// loading// 如果http状态码正常,则直接返回数据//console.log(response)if (response && (response.status === 200 || response.status === 304 || response.status === 400)) {return response.data// 如果不需要除了data之外的数据,可以直接 return response.data}// 异常状态下,把错误信息返回去return {status: -404,message: '网络请求失败,请稍后重试!'}
}
export function checkCode(res) {//console.log(res)// 如果code异常(这里已经包括网络错误,服务器错误,后端抛出的错误),可以弹出一个错误提示,告诉用户// if (res.status == -404) {//     //alert(res.msg)//     Message.error({//         message: res.return_message,//         center: true//     });// }if (res.code  && res.code != '0') {if (res.code == '401') {router.push({path: '/login'})}}return res
}
export function MyPostToken(url, data, token) {// data.timestap = Date.now()return axios({method: 'post',//baseURL: 'https://cnodejs.org/api/v1',url,data: qs.stringify(data),timeout: 65000,headers: {'X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8','token':token ? token:''}}).then((response) => {return checkStatus(response)}).then((res) => {return checkCode(res)})
}
export function MyPostUploadPic(url, data, upload_token) {// data.timestap = Date.now()return axios({method: 'post',url,data: data,timeout: 65000,headers: {Accept: '*/*',Authorization: 'UpToken' + ' ' + upload_token,'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}}).then((response) => {return checkStatus(response)}).then((res) => {return checkCode(res)})
}
export function MyPostQs(url, data) {data.timestap = Date.now()return axios({method: 'post',//baseURL: 'https://cnodejs.org/api/v1',url,data: qs.stringify(data),timeout: 65000,headers: {'X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}}).then((response) => {return checkStatus(response)}).then((res) => {return checkCode(res)})
}
export function MyPost(url, data) {data.timestap = Date.now()return axios({method: 'post',//baseURL: 'https://cnodejs.org/api/v1',url,data: data,timeout: 65000,headers: {'X-Requested-With': 'XMLHttpRequest','Content-Type': 'application/json;charset=UTF-8'}}).then((response) => {return checkStatus(response)}).then((res) => {return checkCode(res)})
}
export function MyGet(url, params) {params.timestap = Date.now()return axios({method: 'get',//baseURL: 'https://cnodejs.org/api/v1',url,params, // get 请求时带的参数timeout: 60000,headers: {'X-Requested-With': 'XMLHttpRequest'}}).then((response) => {return checkStatus(response)}).then((res) => {return checkCode(res)})
}

“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“解决方法相关推荐

  1. Spring Boot——[Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]解决方案

    问题描述 2020-02-13 19:32:04.322 WARN 109508 --- [p-nio-80-exec-4] .m.m.a.ExceptionHandlerExceptionResol ...

  2. jmeter报“msg“:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“的解决方法

    jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supp ...

  3. Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8

    强烈推荐一个大神的人工智能的教程:http://www.captainbed.net/zhanghan [前言] 最近在用restTemplate进行一次http请求时发现了报错(Error whil ...

  4. Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported

    问题描述: 我写了一个接口,这个接口参数是这样的 @ResponseBody @RequestMapping(value = "importData", method = Requ ...

  5. Springboot 报错Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported

    SpringBoot错误解决 1.错误展示 2021-03-23 12:20:02.805 ERROR org.springframework.web.HttpMediaTypeNotSupporte ...

  6. HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n

    问题如下: Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'applicatio ...

  7. 苹果微信推送服务器错误,接入WxPusher微信推送服务出现错误:Content type application/x...

    背景 使用WxPusher微信推送服务 ,可以及时的将服务的一些运行异常信息,发送到自己的微信上,方便了解服务的运行状态(PS:这个服务是免费的). 你可以在这里看到WxPusher微信推送服务的接入 ...

  8. 请求状态为200,前端报系统出错,后端日志报“Content type ‘application/octet-stream‘not supported“错误

    请求后端出现"Content type 'application/octet-stream'not supported"错误 错误描述: Content type 'applica ...

  9. 〖Linux〗Kubuntu, the application 'Google Chrome' has requested to open the wallet 'kdewallet'解决方法...

    每次打开Google都提示: the application 'Google Chrome' has requested to open the wallet 'kdewallet'... 原来是Go ...

最新文章

  1. java 自定义对话框_Java经典实例:用户自定义对话框
  2. CSS使用线性渐变实现滚动进度条
  3. 清空SQL Server数据库中所有表数据的方法(转)
  4. 怎么通过media foundation将图像数据写入虚拟摄像头_不知道怎么挑手机?性价比神机绝对适合你...
  5. 【算法学习笔记】 图(四)用优先级队列优化Dijkstra算法求最短路径(邻接矩阵存储)
  6. HTML的a标签置灰不可点击
  7. linux的常用操作——共享库
  8. 预处理阶乘和阶乘逆元_计算数字的阶乘| 8086微处理器
  9. 查询网站web服务器,web服务器地址查询
  10. 华为云服务器配置教程
  11. 2022年起重机司机(限桥式起重机)新版试题及起重机司机(限桥式起重机)作业考试题库
  12. Actions as Moving Points
  13. 介绍一款功能强大的步进电机控制驱动芯片TMC5240
  14. 普林斯顿大学算法公开课笔记
  15. matlab谐波含量,基于谐波检测中的数字低通滤波器的MATLAB设计
  16. 论文阅读:Enconder-Decoder with Atrous Separabel Convolution for Semantic Image Segmentation(deeplabv3+)
  17. 服务器维护 志愿填报时间顺延,因系统维护耽误考生填报,西藏高考志愿填报截止时间顺延两日...
  18. Before you can run VMware, several modules must be compiled and loaded into the running kernel.
  19. Unity通过刚体组件和C#脚本,施加力实现物体下落并滚离平面 及相机跟随物体
  20. 如何分享CSDN的博客

热门文章

  1. 删除wallet里面登机牌_登机牌丢失问题
  2. xgboost keras_用catboost lgbm xgboost和keras预测财务交易
  3. BP神经网络反向传播手动推导
  4. leetcode 81. 搜索旋转排序数组 II(二分查找)
  5. leetcode 976. 三角形的最大周长
  6. leetcode1169. 查询无效交易
  7. leetcode110. 平衡二叉树(递归)
  8. 异步解耦_如何使用异步生成器解耦业务逻辑
  9. 如何使用浏览器控制台通过JavaScript抓取并将数据保存在文件中
  10. sphinx 项目根目录_如何使用Sphinx工具记录Django项目