reactjs - 在 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 中重写请求正文?在邮递员中效果很好。数组样式中的字段问题
解决方案
如果您在邮递员上正在使用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
})
推荐阅读
- java - 如何使用 Autocomplete Textview 修复 Google Places 建议
- javascript - 刷新或关闭电子表格时,菜单项消失
- javascript - 如何在不执行的情况下测试 jsPerf 上的函数?
- c - 如何得到两个数相乘的结果
- object - 为什么这个类/实例变量没有被初始化?
- operating-system - 操作系统如何确定瞬时时钟速度?
- javascript - 通过忽略特定列将 HTML 表数据转换为 jQuery 中的 JSON 对象
- javascript - Nginx:未捕获的类型错误:无法读取未定义的属性“长度”
- hadoop - Windows 中 Docker 上的 Hortonworks Hadoop 集群
- reactjs - create-react-app - 为什么 localhost 不工作?