在尝试向我的 API 发出请求并检索结果时,我目前在获取函数方面遇到问题。以前没有发生过这种情况,几周前才开始出现这种情况。这是我得到的错误。
[Unhandled promise rejection: TypeError: Network request failed]
- node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:130:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:383:16 in callTimers
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:416:4 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:109:6 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:364:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
这是我正在运行以从 API 检索数据的提取请求的示例。在 Postman 上提出这个请求确实给了我结果,正如开头提到的,它以前也给我结果。
getButtons(token) {
fetch('https://**.**.org/api/v1/requests/***', {
method: 'POST',
headers: {
'token' : this.state.token,
// 'deviceCode' : this.state.device_code,
'qrvalue' : this.state.qr_value,
},
body: JSON.stringify({
'token' : this.state.token
})
}).then(response => response.json().then(data =>({
data: data,
status: response.status
})
).then(res => {
this.setState({
buttons: res.data.options
});
this.renderButtons();
}));
}
欢迎任何建议
答案 0 :(得分:0)
问题是 API 的 SSL 证书已过期,这意味着请求将通过 HTTP 而不是 HTTPS。更新证书允许请求通过 HTTPS,这已经解决了问题。