3

I am trying to build a registration page in react-native which sends the data to an API. Whenever I try filling the form and sending the request, the emulator throws a Network Request Failed error. I am using Android Emulator that comes with Android Studio. I have read almost all related answers but none of them seem to help me. I am working with Android 6.0 API level 23. The code and the error screenshots are attached below. And yes, I have enabled internet permission in manifest file.

handleSignup(event) {
        Alert.alert("Sigup was pressed!");
        fetch(' https://example.com/v1/users/register', {
            method: 'post',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json',
            },
            body: JSON.stringify({
                email: this.state.email,
                password: this.state.password,
                firstName: this.state.firstName,
                lastName: this.state.lastName,
                mobile: this.state.mobile
            })

        })
 .then(response => {
                // console.log('sss', response);
                return response.json();
            })
  .catch((error) => {
         console.error(error);
      });
}

error screenshot on android

Nirmal Dalmia
  • 177
  • 2
  • 12
  • What error exactly? Can you post the log – Dishonered Jun 08 '18 at 04:59
  • Don't post pictures of code or errors. Use the copy button and post it here, we can't read that. – Gabe Sechan Jun 08 '18 at 05:04
  • @GabeSechan the copy button there isn't working! That's the reason I had to take a screenshot and post. I am sorry if it's a little hard for you to read. Kindly bear with it. – Nirmal Dalmia Jun 08 '18 at 05:48
  • Your url is likely wrong https://example.com/v1/users/register is very unlikely to actually exist, since example.com isn't a real website. It's a reserved name for made up examples – Gabe Sechan Jun 08 '18 at 05:50
  • Actually the url is something different. I've replaced the actual website address with example for the purpose of security. The API works perfectly fine with postman. – Nirmal Dalmia Jun 08 '18 at 05:56
  • Check error logs in your Android Studio what exactly error is. I faced this issue because of a security issue in some Android Devices. If it is same as my issue then refer this links https://stackoverflow.com/questions/39133437/sslhandshakeexception-handshake-failed-on-android-n-7-0 and https://developer.android.com/training/articles/security-ssl – Vishal Jadav Jun 08 '18 at 07:08
  • Where you able to solve this? – J. Hesters Sep 07 '18 at 11:22
  • @J.Hesters I quit the project and started a new one. I am not sure what caused the error but there was some error even on the server side. Not exactly sure whether it was React Native or the API that was causing the issue. – Nirmal Dalmia Sep 10 '18 at 17:10

0 Answers0