简体   繁体   中英

Saga Redux not sending parameters in post

I'm using redux Saga for the first time for handling my API requests. I've got an async function that sends a simple post request like so:

const onLoginRequest = async (userName, password) =>
await fetch(`${loginApi}`, { method: 'POST', body: { userName:userName,password:password } })
  .then(res => res.json())
  .then(res => res)
  .catch(error => error);

if I send the userName and password in the querystring, it works fine. But when adding them to the Body of my POST, it shouts that they are undefined.

Any idea what I am doing wrong?

Make sure you are serialize the JSON body like below

body: JSON.stringify({
  userName: userName,
  password: password
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM