Fetch doesn't work in React Native ios -
i have login function in react native try fetch data. function follows:
onlogin: function() { // const self = this; self.setstate({modalvisible: true, modalmessage: 'signing in'}); fetch('http://psa.autralis.com/manager/api/v1/obtain-auth-token/', { method: 'post', headers: { 'content-type': 'application/json', }, body: json.stringify({ username: self.state.username, password: self.state.password, }) }) .then(response => response.json()) .then(data => console.log(data)) .catch((error) => { console.warn(error); }); },
but reason doesn't work on ios. error :
on android works, , tested postman , there works.
any idea?
the reason problem that: ios not allow http requests default, https. if need http, change info.plist:
<key>nsapptransportsecurity</key> <dict> <key>nsallowsarbitraryloads</key> <true/> </dict>
Comments
Post a Comment