2

我为我的应用程序使用基于会话的身份验证系统,我的 API 调用工作得很好,但是,当使用这个请求图像时:

<Image source={{uri: 'https://facebook.github.io/react/logo-og.png'}}
       style={{width: 400, height: 400}} />

请求未经过身份验证

但是,需要进行身份验证才能检索图像。你会怎么做?似乎没有任何专门针对此的文档

4

1 回答 1

6

您可以使用图像源传递标头:

<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"];
})
于 2018-08-24T21:53:00.547 回答