如何在react-redux中使用获取来发送数据

Scu*_*sf0 1 reactjs redux fetch-api

我正在执行多个复选框过滤器,并且必须使用post方法将一个对象发送到服务器。我如何使用提取来做到这一点?我可以使用提取发送数据吗?从服务器我必须收到一个过滤列表。谢谢!

Han*_*rus 5

是的,您可以使用“ 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);
      });
  }
Run Code Online (Sandbox Code Playgroud)