提交 5b61f89c 编写于 作者: 雪洛's avatar 雪洛

fix: 钉钉小程序真机使用uni.request时设置content-type为application/json报错的Bug askId:...

fix: 钉钉小程序真机使用uni.request时设置content-type为application/json报错的Bug askId: https://ask.dcloud.net.cn/question/97570
上级 a1b9912f
import {
isPlainObject
} from 'uni-shared'
// 不支持的 API 列表
const todos = [
// 'getRecorderManager',
......@@ -86,6 +89,7 @@ const protocols = { // 需要做转换的 API 列表
request: {
name: my.canIUse('request') ? 'request' : 'httpRequest',
args (fromArgs) {
const method = fromArgs.method || 'GET'
if (!fromArgs.header) { // 默认增加 header 参数,方便格式化 content-type
fromArgs.header = {}
}
......@@ -103,8 +107,8 @@ const protocols = { // 需要做转换的 API 列表
}
},
data (data) {
// 钉钉在content-type为application/json时,不会自动序列化
if (my.dd && headers['content-type'].indexOf('application/json') === 0) {
// 钉钉小程序在content-type为application/json时需上传字符串形式data,使用my.dd在真机运行钉钉小程序时不能正确判断
if (my.canIUse('saveFileToDingTalk') && method.toUpperCase() === 'POST' && headers['content-type'].indexOf('application/json') === 0 && isPlainObject(data)) {
return {
name: 'data',
value: JSON.stringify(data)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册