无法使用React Native Fetch的PUT方法使用FormData

时间:2019-10-18 12:20:34

标签: javascript react-native https http-headers

我尝试使用PUT方法获取信息以更新表单,但返回的结果是网络请求失败。 当我在邮递员上发送我的修改时,它起作用了。 我添加正文后:JSON.stringify(data)我得到响应但成功失败,结果是:_parts:[“ PARAM_NOT_AUTHORIZED”] 似乎与FormData()的标头有关的某些问题? 有什么解决办法吗? 这是我的代码:

handelSave = () => {
    this.props.showModal();
    const url = `${API_URL}/users/me`;
    const data = new FormData();
    data.append("profile.pseudo", this.profileData.pseudo);
    data.append("profile.email", this.profileData.email);
    if (this.profileData.description) {
      data.append("profile.description", this.profileData.description);
    }
    if (this.profileData.firstName) {
      data.append("profile.firstName", this.profileData.firstName);
    }

    console.log(data);
    fetch(url, {
      method: "PUT",
      headers: {
        Accept: 'application/json',
        "Content-Type": "application/json",
        "X-Auth-Token": this.props.token
      },
      body: data
    })
      .then((response) => response.json();
      })
      .then((responseJson) => {

      })
      .catch((error) => {
        console.log(error.message);

      });
  };```

0 个答案:

没有答案