首页 > 解决方案 > 在 redux-saga 中发出 post 请求:请求正文的问题

问题描述

我想在 redux-saga 中发出 post 请求。我的代码如下所示:

const response = yield fetch('https://test.api/test', {
  method: 'POST',
  body: JSON.stringify({
    'auth[email]': 'test@test.test',
    'auth[password]': 'test'
  }),
});

如何在 redux-saga 中重写请求正文?在邮递员中效果很好。数组样式中的字段问题

标签: reactjshttpreduxredux-saga

解决方案


如果您在邮递员上正在使用form-data并且它正在工作,那么您应该在调用时做同样的事情fetch

var formData = new FormData();
formData.append('auth[email]', 'test@test.test');
formData.append('auth[password]', );

const response = yield fetch('https://test.api/test', {
  method: 'POST',
  body: formData
})

推荐阅读