【发布时间】:2019-03-01 00:14:31
【问题描述】:
我正在开发一个 React Native App 发出 http / https 请求。我正在为Android和iOS两个平台做。我面临一个问题,不允许我使用自签名证书获取 url。我已经测试过这适用于其他非自签名的 url。有办法强制 React Native 信任自签名证书吗?
我在执行fetch() 函数时遇到的错误是这样的:
TypeError: Network request failed
我在这里发布我的代码:
const form = new FormData();
form.append('parameters[ticketPerson]', this.state.ticketPerson);
form.append('rawxmlresponse', 'false');
fetch(this.state.url, {
method: 'POST', headers: { Connection: 'close' },
body: form,
})
.then(response => response.json())
.then(async (responseJson) => {
console.log('repsonse --->', responseJson);
})
.catch((error) => {
console.log('ERROR ---> ', error);
});
它适用于 iOS,仅在 Android 上失败。如果 url 不是自签名证书,则此代码适用于 Android。
避免诸如“您不应该信任”或“只需签名即可使用”之类的回答。
【问题讨论】:
-
证书的主要目的是确保与正确的站点对话。如果您接受自签名证书,您将完全放松。所以即使你不想听到:“你不应该相信”。
-
谢谢你
-
你有没有设法解决这个问题?面临类似问题。
-
我不得不在服务器端更改证书。由于 TSL2,我也遇到了类似的问题,因为 Android
标签: android react-native ssl fetch self-signed