日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/9 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 “Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“解决方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目接口返回
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“解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。