反应本机获取请求获取状态文本未定义

时间:2018-02-12 13:00:28

标签: http react-native http-error

我是React Native的新手,我正在使用params调用API。它看起来像这样。

   async onSendClick() {

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

    let subject = "Feedback Form"
    let senderEmail = 'test@test.com'
    let fromEmail = 'us@test.com'
    let replyTo = 'customer@test.com'
    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)); 
      })
  }

在响应部分中,我收到了statusText的404错误:undefined。请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

您必须对URI进行编码。否则它将无法工作。 有关javascript中URL编码的详细信息,请关注this link