如果在企业中 用到的 所有请求都是POST,你也不要慌张,因为POST的安全系数要高一点
那么 为了让请求 能正常发出去,在微信小程序和 uniapp中 我们都需要在请求头中 做设置
微信小程序:
wx.request({
....
header:{
'content-type': 'application/x-www-form-urlencoded', // 默认值转换请求为post请求,
}
})
以上只是 官网的 请求方式,如果是自己封装的请求方式 和上面一样 默认值转换请求为 POST请求
uniapp:我这里用到的是 别人封装好的请求方式
封装好的地址是这个:@escook/request-miniprogram - npm
/* 设置请求拦截器 */
$http.beforeRequest = function(options){
// 默认值转换请求为post请求,
options.header['Content-Type'] = "application/x-www-form-urlencoded"
/* 在相应拦截中添加请求头 openid*/
options.header.Authorization = `Bearer ${store.state.storeUserinfor.openid}`
//添加提示信息
uni.showLoading({
title:'数据加载中..'
})
/* 响应拦截器*/
$http.afterRequest = function(options){
//关闭提示信息
uni.hideLoading()
}
}