I'm trying to make POST call from my SPA to a Flask backend. I am able to make the call successfully from the Postman but the exact same call fails with Axios. As I can see both of them generate a little different cURL command. Anyone know what is the matter here?
Here is how I'm making my Axios call.
export function login(email, password) {
return axios.post('www.app.com/login', {
email, password
})
};
Here is the cURL generated in the browser network tab, which doesn't work as expected.
curl 'https://www.myapp.com/login' -H 'Host: somesite.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0' -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: http://localhost:3000/' -H 'Content-Type: application/json' -H 'Origin: http://localhost:3000' -H 'Connection: keep-alive' --data '{"email":"me@hello.com","password":"hello"}'
Here is the cURL generated by Postman which works.
curl -X POST \
http://www.myapp.com/login \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-H 'postman-token: c85019e0-55ed-9124-9f46-f006b22e4d56' \
-F email=hello@hello.com \
-F password=hello
I can see that the Postman call has a -F
option which is not there in my Axios call. Any help is appreciated.