Post redux-saga 中的请求不工作,似乎什么也没发生
Post request in redux-saga not working, nothing seems to happen
我想在 redux-saga 中发出 post 请求。我的代码如下所示:
var formdata = new FormData();
formdata.append("points", "a,b");
formdata.append("pid", "someid");
formdata.append("tions", "cses");
formdata.append("exp", "cx");
const ans = yield call(fetch,
'http://localhost:8000/api',
{
method: "POST",
headers: { 'Authorization': 'Token tokenid',
"Content-Type": "application/json",},
body : formdata
});
在 Postman 中它工作正常(在 body 中选择 form-data
),但在 saga 中,POST 请求根本没有发生。
请指出我哪里做错了?
问题出在 server-side 上的异常,当您抛出错误时 headers 未设置。因此,您应该做的是仅使用 400 个错误请求响应获取请求的 CORS 错误。
Update :- 我在 headers 中添加 "Content-Type": "application/x-www-form-urlencoded"
并相应更改 body 类型后,400 错误请求消失了
示例:-
fetch("api/xxx", {
body: "email=test@example.com&password=pw",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
method: "post",
}
我想在 redux-saga 中发出 post 请求。我的代码如下所示:
var formdata = new FormData();
formdata.append("points", "a,b");
formdata.append("pid", "someid");
formdata.append("tions", "cses");
formdata.append("exp", "cx");
const ans = yield call(fetch,
'http://localhost:8000/api',
{
method: "POST",
headers: { 'Authorization': 'Token tokenid',
"Content-Type": "application/json",},
body : formdata
});
在 Postman 中它工作正常(在 body 中选择 form-data
),但在 saga 中,POST 请求根本没有发生。
请指出我哪里做错了?
问题出在 server-side 上的异常,当您抛出错误时 headers 未设置。因此,您应该做的是仅使用 400 个错误请求响应获取请求的 CORS 错误。
Update :- 我在 headers 中添加 "Content-Type": "application/x-www-form-urlencoded"
并相应更改 body 类型后,400 错误请求消失了
示例:-
fetch("api/xxx", {
body: "email=test@example.com&password=pw",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
method: "post",
}