uni.request({
url: "http://47.114.145.32:8400/sys/sms/sendSmsCode",
header: {
"Content-Type": "application/json"
},
data: {
phone: '18600000000',
typeCode: 'LOGIN'
},
method: 'POST',
timeout: 30000,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})

- 发布:2020-11-26 12:47
- 更新:2020-11-26 17:03
- 阅读:2102
【报Bug】uniapp编译到安卓APP,http 请求头Content-Type: "application/json" 会默认加上;charset=UTF-8
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 2.9.11
手机系统: Android
手机系统版本号: Android 10
手机厂商: 小米
手机机型: 小米10
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
uni.request({
url: "http://47.114.145.32:8400/sys/sms/sendSmsCode",
header: {
"Content-Type": "application/json"
},
data: {
phone: '18600000000',
typeCode: 'LOGIN'
},
method: 'POST',
timeout: 30000,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
uni.request({
url: "http://47.114.145.32:8400/sys/sms/sendSmsCode",
header: {
"Content-Type": "application/json"
},
data: {
phone: '18600000000',
typeCode: 'LOGIN'
},
method: 'POST',
timeout: 30000,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
预期结果:
uni.request({
url: "http://47.114.145.32:8400/sys/sms/sendSmsCode",
header: {
"Content-Type": "application/json"
},
data: {
phone: '18600000000',
typeCode: 'LOGIN'
},
method: 'POST',
timeout: 30000,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
uni.request({
url: "http://47.114.145.32:8400/sys/sms/sendSmsCode",
header: {
"Content-Type": "application/json"
},
data: {
phone: '18600000000',
typeCode: 'LOGIN'
},
method: 'POST',
timeout: 30000,
success: (res) => {
console.log(res)
},
fail: (err) => {
console.log(err)
}
})
实际结果:
header: {Content-Length: "56", Content-Type: "application/json;charset=UTF-8"}
header: {Content-Length: "56", Content-Type: "application/json;charset=UTF-8"}
bug描述:
uniapp编译到安卓APP,http 请求头Content-Type: "application/json" 会默认加上;charset=UTF-8,导致服务端接口识别不了,怎么去掉这个后缀