I'm using axios to perform get and post requests to an external api, i have finally succeed to achieve get request (problem with the ssl certificate, i avoid it by adding this : httpsAgent: new https.Agent({ rejectUnauthorized: false }),
now i would like to post the api,
to get the request working in postman, i put in headers content-type : application/json and in the body : {}
when trying with a google chrome extention, to make it work, i put nothing in the headers but in params, i select customer : application/json and i put inside this {} instead of the default choice which is x-www-form-urlencoded;charset=UTF-8
in my javascript app i tried this
var url = https://10.11.31.100:9440/api/nutanix/v3/images/list;
axios({
method:'post',
httpsAgent: new https.Agent({ rejectUnauthorized: false }),
url,
auth: {
username: '******',
password: '********'
},
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
params: {},
data: {}
})
.then(function (response) {
res.send(JSON.stringify(response.data));
console.log(response);
})
.catch(function (error) {
console.log(error);
});
I get this problem :
TypeError : UTF-8 is not a function
TypeError : UTF-8 is not a functionis printed by the.catch()? What's the point of theX-Requested-With': 'XMLHttpRequestheader? This code seems ok to me. - Andrea Franchiniconst randomName = 'foobar'=>randomName()- Andrea Franchini