I am replacing the deprecated 'request' package of npm with 'axios' latest in Node 16.15.x application.
However, I am facing an issue with one POST request sent via axios (other POST requests I was able to implement)
Here is code using 'request' package POST
request.post('https://sampleserver6.arcgisonline.com/arcgis/tokens/generateToken', {
form: {
'username': 'user1',
'password': 'user1',
'client': 'requestip',
'expiration': 60,
'f': 'json',
}
}, (err, response, body) => {
console.log('****Token', body)
})
This gives the expected response. Which is a token. I am using a sample REST server "https://sampleserver6.arcgisonline.com/arcgis/tokens/generateToken"
Now when trying the same POST request using 'axios' POST,
axios.post('https://sampleserver6.arcgisonline.com/arcgis/tokens/generateToken', {
'username': 'user1',
'password': 'user1',
'client': 'requestip',
'expiration': 60,
'f': 'json',
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
.then(function(response) {
console.log('****Token', body)
})
The response is 200 however the response data shows an error as "Invalid request Usage: https://sampleserver6.arcgisonline.com/arcgis/tokens?request=gettoken&username=username&password=password&"
This is the same error on the sample REST server as well when you put no values/partial values in the form and click 'Generate Token'. So it seems 'axios' is not able to put form data as expected.
Am I using the correct implementation in 'axios' POST?
I have tried using the 'form-data' package as well -> same error
I have tried different Content-Type -> Issue persists