反应本地android网络请求失败,但在ios和postman上工作

时间:2019-07-28 04:53:07

标签: react-native expo

我有一个可以在ios设备,ios模拟器和邮递员上良好运行的api。但它无法与android设备和android模拟器一起使用。

这是我的api https://cloud.vegasegamingclub.com/proxy/neon/checkpin发布方法

这就是我在应用中执行的操作

async componentDidMount() {
    try {
        let res = await fetch('https://cloud.vegasegamingclub.com/proxy/neon/checkpin', {
            method: 'post',
        })
            console.log('res', res)
    } catch (error) {
        console.log('error', error)
    }
}

这段代码在ios和post man上运行良好,但在android上失败,我收到了此错误

Network request failed
- node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:504:29 in onerror
- node_modules/event-target-shim/lib/event-target.js:172:43 in dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:578:29 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:392:25 in __didCompleteResponse
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:191:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:349:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:297:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

我也尝试过替换fetch axios,同样的错误。

1 个答案:

答案 0 :(得分:0)

答案是获取API的某些ssl出现了问题。选项1要求开发人员更改证书类型。

选项2使用https://www.npmjs.com/package/react-native-fetch-blob