i want to build a app with react native for whmcs and i use the whmcs api but i cant send the request parameters as data?!!! when i set the parameters in url the request work fine but in data whmcs not read my parameters
axios({
method: 'post',
url: baseUrl+`?action=GetClientsProducts&username=${UserName}&password=${Password}&accesskey=${accessKey}&responsetype=json&clientid=${this.state.user_token}`,
}).then(function(response) {
console.log(response);
self.setState({
data:response.data.products.product,
load:true
})
})
.catch(function(error) {
console.log(error.response);
self.setState({refresh:true,})
}); //this is work fine
//
But in data not work???
let myData={username:'myusername',password:'mypassword',accesskey:'myaccesskey',responsetype:'json',...}
axios({
method: 'post',
url: baseUrl,
data:myData
})
The data
parameter send the provided object as the body of the request. You're trying to send query params, to do this you'll need to use theaxios.post
function like so:
axios.post(baseUrl, null, {
params : {
username : 'username',
password : 'password',
accesskey : 'key',
responseType : 'json'
}
});
You could also do the same with the axios
function but moving your query params from the data
parameter to the params
as shown above.