我想使用whmcs的react native构建一个应用程序,我使用whmcs api,但是我无法将请求参数作为数据发送? 当我在url中设置参数时,请求工作正常,但在数据whmcs中无法读取我的参数
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
//
但是在数据中不起作用?
let myData={username:'myusername',password:'mypassword',accesskey:'myaccesskey',responsetype:'json',...}
axios({
method: 'post',
url: baseUrl,
data:myData
})
答案 0 :(得分:0)
data
参数将提供的对象作为请求的正文发送。您正在尝试发送查询参数,为此,您将需要使用axios.post
函数,如下所示:
axios.post(baseUrl, null, {
params : {
username : 'username',
password : 'password',
accesskey : 'key',
responseType : 'json'
}
});
您也可以使用axios
函数执行相同的操作,但是将查询参数从data
参数移动到params
,如上所述。