你可以尝试这样的数据发送到服务器(POST)
let response = await fetch(
'http://your_url', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: this.state.name,//data which u want to send
password: this.state.password,
})
});
let responseText = await response.text();
if (response.status >= 200 && response.status < 300){
Alert.alert('Server response', responseText)
}
else {
let error = responseText;
throw error
//Alert.alert('Login', error)
}
} catch(errors) {
Alert.alert('Login', errors)
Actions.Documents();
}
编辑:作为最新的iOS SDK强制连接到在HTTPS协议,而不是http.you可以添加一个例外域内, Xcode项目的info.plist文件。
,如果你想允许的一切写这里面的info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>yourdomain.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
更多信息检查了这一点https://stackoverflow.com/a/31623388/7604342
现在编辑我的答案检查它 –
在哪个info.plist文件中我必须添加App Transport安全例外? 因为应用程序文件夹中有更多info.plist文件。 –
搜索AppName-Info.plist,其中AppName是您的应用的名称。 –