0

I am using the following fetch call in a react native app:

fetch(apiUrls.signInUrl, {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    user: {
      email: username,
      password: password,
    }
  })
})
.then(response => {
  response.json().then(responseJson => {
    dispatch(AccountActions.loginResponse(username, password, responseJson.token, response.status));
    dispatch(CardActions.getCards(username, responseJson.token));
  });
})
.catch(err => {
  console.error(err);
});

The fetch call is failing with the following error screen. Any help? enter image description here

4
  • Have you tried using a proxy like Charles to inspect network traffic? stackoverflow.com/a/35047215/869895 Commented Sep 3, 2016 at 12:30
  • 1 - Can you access the internet from safari on the simulator/phone? 2 - is the internet working on your computer? 3 - Is your internet working at all? Commented Sep 3, 2016 at 14:42
  • internet is working. other api calls in the same app are working fine. even the same api call, if I press the login button again, it works fine. Commented Sep 3, 2016 at 15:01
  • After I installed Charles root certificate in iOS simulator, it seems to be working fine. The first call was always the one giving me the problem. Even that seems to be resolved now. I am going to close this question. @alexp, Thanks for Charles proxy suggestion. Commented Sep 3, 2016 at 15:33

1 Answer 1

1

In IOS http connections are disabled by default. So you would have to enable it. Though it isn't recommended, it should be fine for debug mode.

Here are the steps: 1. You go to Info.plist file of your iOS project in Xcode

  1. Change allow Arbitrary loads to "YES" enter image description here

  2. Optionally you can also add your trusted host to exception domains if you don't like to enable "allow arbitrary loads" option

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.