使用react redux获取删除请求方法不会删除

Fetch delete request method using react redux is not deleting

我正在尝试使用 fetch delete 请求方法通过 react redux 删除我的本地主机服务器中的项目

调用方法

 deleteItem(e) {
    e.preventDefault();
    const id = this.props.id;
    this.props.deleteSet(id);
  }

正在调度操作

const mapDispatchToProps = dispatch => ({
  deleteSet: id => dispatch(deleteSet(id)),
});

动作

export function deleteSetSuccess(id) {
  return {
    type: "DELETE_SET_SUCCESS",
    id,
  };
}

export function deleteSet(data) {
  return (dispatch) => {
    fetch(`${apiUrl}orgs/1/sets/${data}`, {
      method: "DELETE",
      body: JSON.stringify(data),
      headers: new Headers({
        "Content-Type": "application/json",
      }),
    }).then(response => response)
      .then(id => dispatch(deleteSetSuccess(id)));
  };
}

减速器

export function deleteSetSuccess(state = '', action) {
  switch (action.type) {
    case "DELETE_SET_SUCCESS":
      return action.id;

    default:
      return state;
  }
}

来自本地主机服务器的响应

DELETE http://localhost:8080/distinction-2.0-alpha2/api/orgs/1/sets/8 400 (Bad Request)

A​​ valid HTTP DELETE request doesn’t have a request body——因此也不需要 Content-Type 请求 header——但是问题中的请求代码正在发送一些数据作为请求 body,以及 Content-Type 请求 header。据推测,您的服务器认为这不是一个有效的 DELETE 请求,因此它以 400“错误请求”作为响应以表明这一点。