Closed liwenjun95 closed 3 years ago
改成这样
ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
谢谢 大佬
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
请求头没Authorization
然后你看一下这里的文档:请求锁。。在一些平台上发的文档比较旧。。
我看你的截图,wrapper 函数第二个参数是不需要传的
prequest.use(async (ctx, next) => {
if (ctx.request.skipTokenCheck) return next()
const token = await wrapper(() => prequest('/token', { skipTokenCheck: true }).then(res => res.data))
ctx.request.headers = ctx.request.headers || {}
ctx.request.headers['Authorization'] = `bearer ${token}`
await next()
})
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
谢谢 大佬
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
请求头没Authorization
小程序里是 header, 不是 headers
小程序参数列表,看一下这个文档:https://pre-quest.vercel.app/#/miniprogram
然后你看一下这里的文档:请求锁。。在一些平台上发的文档比较旧。。
我看你的截图,wrapper 函数第二个参数是不需要传的
prequest.use(async (ctx, next) => { if (ctx.request.skipTokenCheck) return next() const token = await wrapper(() => prequest('/token', { skipTokenCheck: true }).then(res => res.data)) ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = `bearer ${token}` await next() })
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
谢谢 大佬
改成这样
ctx.request.headers = ctx.request.headers || {} ctx.request.headers['Authorization'] = 'Bearer' + 'xxx'
请求头没Authorization
小程序里是 header, 不是 headers
OK了 谢谢 大佬指导!!
请求token接口获取到token,赋值给ctx.request.headers['Authorization'] 时报Unhandled promise rejection TypeError: Cannot set property 'Authorization' of undefined