Reputation:
I used request and wrap it with a promise, but I want to write cleaner code using axios, somehow I got internal serval error (Request failed with status code 401), I don't have access to backend code I have no clue what is going on.
//worked
response = yield new Promise(resolve => {
resolve(request.post(api, {form: {id: 1, user: 1}}))
})
//doesn't work
response = yield axios.post(api, {id: 1, user: 1})
Upvotes: 0
Views: 1406
Reputation: 22553
Ahh, you are sending an application/x-www-form-urlencoded request! Turns out it's not so easy with axios. Here in the readme:
https://github.com/axios/axios#using-applicationx-www-form-urlencoded-format
There are a number of techniques described there. Here is one that works on the server side in node:
var querystring = require('querystring')
axios.post('/foo', querystring.stringify({id: user: 1})
Looks like in this case, request gives you the cleaner looking code!
Upvotes: 1