你可以嘗試這樣的數據發送到服務器(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是您的應用的名稱。 –