I would like to make post request in redux-saga
. My code looks like:
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
});
In Postman it is working fine(selected form-data
in body) but in saga, the POST request is giving error as the server responded with a status of 400 (Bad Request)
Please suggest where I am doing wrong as the API is working fine and all the parameters are correct?
Top comments (2)
Update :- The 400 Bad request has gone away after I added
"Content-Type": "application/x-www-form-urlencoded"
in the headers and changed the body type accordinglyExample :-
body : JSON.stringify(formdata)