浏览代码

fix: formData

wanggaokun 1 年之前
父节点
当前提交
d7dad37307
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      src/api/index.ts

+ 5 - 0
src/api/index.ts

@@ -31,6 +31,7 @@ const config = {
 const encryptHeader = 'encrypt-key'
 // 是否显示重新登录
 export let isReLogin = { show: false }
+axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
 axios.defaults.headers['clientid'] = import.meta.env.VITE_APP_CLIENT_ID
 const axiosCanceler = new AxiosCanceler()
 
@@ -105,6 +106,10 @@ class RequestHttp {
           config.headers[encryptHeader] = encrypt(encryptBase64(aesKey))
           config.data = typeof config.data === 'object' ? encryptWithAes(JSON.stringify(config.data), aesKey) : encryptWithAes(config.data, aesKey)
         }
+        // FormData数据去请求头Content-Type
+        if (config.data instanceof FormData) {
+          delete config.headers['Content-Type']
+        }
         return config
       },
       (error: AxiosError) => {