response of react native get request gets status text undefined

1.3k views Asked by At

I'm new to React Native and I'm calling an API with params. It looks like this.

   async onSendClick() {

    AsyncStorage.getItem('@Token:key').then((token) => {
    console.log("console is " + token)

    let subject = "Feedback Form"
    let senderEmail = '[email protected]'
    let fromEmail = '[email protected]'
    let replyTo = '[email protected]'
    let url = BASE_URL +  '/email/send?'
    let params = "subject=" + subject + "&email=" +senderEmail +  "&fromEmail=" + fromEmail + "&replyTo=" + replyTo + "&content=" + feedBackMessage


    return fetch(url + params , {
        method: 'GET',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + token
          },
        }).then((responseOne) => {
            console.log(responseOne)
        if (responseOne.status == 200) {
            console.log("success")
        } else{
          console.log("error")
        }
        }).catch((error) => console.error("ERROR" + error)); 
      })
  }

In the response section , I'm getting 404 error with statusText: undefined. Please help me to fix this issue.

1

There are 1 answers

0
srs On

You must encode the URI. Otherwise it will not work. Follow this link for more info about URL encoding in javascript.