如何在Whmcs的React Native应用程序中发送发布请求

时间:2020-01-13 13:03:33

标签: reactjs react-native whmcs

我想使用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
    })

1 个答案:

答案 0 :(得分:0)

data参数将提供的对象作为请求的正文发送。您正在尝试发送查询参数,为此,您将需要使用axios.post函数,如下所示:

axios.post(baseUrl, null, {
    params : {
        username : 'username',
        password : 'password',
        accesskey : 'key',
        responseType : 'json'
    }
});

您也可以使用axios函数执行相同的操作,但是将查询参数从data参数移动到params,如上所述。

相关问题