React-Native:使用JSON.stringify的POST调用不起作用

时间:2019-05-15 15:58:10

标签: javascript react-native react-native-ios

我有这样的HTTP POST呼叫

 static login(email, pw, callback) {
    let url = APIConfig.BASE_URL + APIConfig.LOGIN
    console.log(url);
    fetch(url, {
      method: HTTPMethod.POST,
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        username: email,
        password: pw
      })
    })
      .then(response => response.text())
      .then(responseText => {
        console.log(responseText);
        callback(null, null);
      })
      .catch(error => {
        callback(null, error);
        console.log(error);
      });
    }

我这样称呼

NetworkManager.login("username_abcd", "pw_xyz", () => {
    ....
});

它给我403错误,但是如果我将硬编码参数设为

body: JSON.stringify({
        username: "username_abcd",
        password: "pw_xyz"
      })

工作正常。我在做什么错了:|

0 个答案:

没有答案