使用 cookie 响应本机图像 uri 请求
React native image uri request with cookie
我为我的应用程序使用了基于会话的身份验证系统,我的 API 调用工作得很好,但是,当使用此请求图像时:
<Image source={{uri: 'https://facebook.github.io/react/logo-og.png'}}
style={{width: 400, height: 400}} />
请求未通过身份验证
但是需要身份验证才能检索图像。你会怎么做?似乎没有专门针对此的任何文档
您可以通过 headers 图片来源:
<Image source={{
uri: 'https://facebook.github.io/react/logo-og.png',
headers: {
Cookie: 'cookie data here',
}
}}>
从您的 API 回复中获取您的 cookie:
fetch('apicall').then(res => {
cookieData = res.headers.map["set-cookie"];
})
我为我的应用程序使用了基于会话的身份验证系统,我的 API 调用工作得很好,但是,当使用此请求图像时:
<Image source={{uri: 'https://facebook.github.io/react/logo-og.png'}}
style={{width: 400, height: 400}} />
请求未通过身份验证
但是需要身份验证才能检索图像。你会怎么做?似乎没有专门针对此的任何文档
您可以通过 headers 图片来源:
<Image source={{
uri: 'https://facebook.github.io/react/logo-og.png',
headers: {
Cookie: 'cookie data here',
}
}}>
从您的 API 回复中获取您的 cookie:
fetch('apicall').then(res => {
cookieData = res.headers.map["set-cookie"];
})