如何在 react-redux 中使用 fetch 发送数据

How to send data with fetch in react-redux

我正在做一个多复选框过滤器,我必须用 post 方法向服务器发送一个对象。我怎样才能使用 fetch 来做到这一点?我可以使用 fetch 发送数据吗?我必须从服务器接收过滤列表。 谢谢!

是的,您可以使用 'POST'

指定获取方法

示例代码来自 https://facebook.github.io/react-native/docs/network.html

function getMoviesFromApiAsync() {
    return fetch('https://mywebsite.com/endpoint/', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        firstParam: 'yourValue',
        secondParam: 'yourOtherValue',
      })
    }).then((response) => response.json())
      .then((responseJson) => {
        return responseJson.success;
      })
      .catch((error) => {
        console.error(error);
      });
  }