微信小程序返回的登录信息中Set-Cookie字段值之间是用‘,’连接的,而需要返回给服务器的则是';' 故需要自己进行转换
登录时保存:
import Taro from '@tarojs/taro'
Taro.request({
url:'xxxxx',
method:'xxxx',
data:{
loginName:'xxxx',
password: xxxx,
},
header: {
'content-type': 'xxxx'
}
}).then(json => {
let cookies = json.header['Set-Cookie'].replace(/,/g, ';')
console.log('=======', cookies)
Taro.setStorageSync('Cookies', cookies)
})
请求信息时带上已经保存的Cookie
let cookie = Taro.getStorageSync('Cookies')
Taro.request({
url:'https://www.ivideohome.com/api/diy/get_app_list',
method:'GET',
header:{'Cookie': cookie,
'content-type':'application/json'}
}).then((userRes) => {
console.log('-----applist---------', userRes)
})
网友评论