【问题标题】:response of react native get request gets status text undefinedreact native get请求的响应获取状态文本未定义
【发布时间】:2018-02-12 13:00:27
【问题描述】:

我是 React Native 的新手,我正在使用参数调用 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)); 
      })
  }

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

【问题讨论】:

    标签: http react-native http-error


    【解决方案1】:

    您必须对 URI 进行编码。否则它将无法正常工作。 关注this link,了解更多关于 javascript 中 URL 编码的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多