用token和ttl反应原生图像

时间:2018-03-23 21:25:02

标签: image react-native token

我正在尝试从以下网址获取图片:https://mangatown.secure.footprint.net/store/manga/8921/cover.jpg?token=83a7fa7598faf5b7aae40e3c935e0cd95a019adc&ttl=1521921600&v=1521696105

但我只得到一个空洞的结果,

我尝试使用该技术获取url以将其更改为base64并将base64作为图像注入,但无法使提取工作。

fetch("https://mangatown.secure.footprint.net/store/manga/8921/cover.jpg", {
  method: 'GET',
  headers: {
    'token': '83a7fa7598faf5b7aae40e3c935e0cd95a019adc',
    'ttl':'1521921600',
    'v':"1521696105"
  }
}
).then((res) => res.text())
.then((content) => {
    this.setState({
      base64: content
    })
})
.catch(err => console.log(err))

但只有这个错误:

TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (fetch.js:441)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:554)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:387)
at XMLHttpRequest.js:493
at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
at MessageQueue.__callFunction (MessageQueue.js:353)
at MessageQueue.js:118
at MessageQueue.__guardSafe (MessageQueue.js:316)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:117)

(如此处所述:React Native Image with 'Bearer' authentication token

是否有人知道如何使其与这种身份验证图像一起使用?

我的代码很简单:

<Image style={{width:300, height:300}} resizeMode="contain" source={{ uri: https://mangatown.secure.footprint.net/store/manga/8921/cover.jpg?token=83a7fa7598faf5b7aae40e3c935e0cd95a019adc&ttl=1521921600&v=1521696105 }} />

没有令牌的相同代码完美无缺:

 <Image style={{width:300, height:300}} resizeMode="contain" source={{ uri: "https://demo.phpgang.com/crop-images/demo_files/pool.jpg" }} />

非常感谢

0 个答案:

没有答案