React Native image from URL that requires headers

怎甘沉沦 提交于 2021-01-28 05:28:02

问题


I need to display an Image component where the source is a URL that requires http headers passed on to fetch it (for authentication purposes).

How could this be implemented in RN?

Is there a way to add headers to the source?


回答1:


This has been added to react-native. See here:

https://reactnative.dev/docs/images.html#network-requests-for-images

Example in link:

<Image
  source={{
    uri: 'https://reactjs.org/logo-og.png',
    method: 'POST',
    headers: {
      Pragma: 'no-cache',
    },
    body: 'Your Body goes here',
  }}
  style={{width: 400, height: 400}}
/>


来源:https://stackoverflow.com/questions/60711802/react-native-image-from-url-that-requires-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!