带密码的AJAX请求

带密码的AJAX请求,ajax,ssl,curl,passwords,axios,Ajax,Ssl,Curl,Passwords,Axios,我有以下PHP/CURL。我需要通过JS/AJAX(Axios)发送它 如何适应JS 要与一起使用,请使用auth进行基本身份验证: axios({ method: 'get', url: 'https://example.com/pc_api/index.php/token', responseType: 'json', // default is json auth: { username: 'test', password:

我有以下PHP/CURL。我需要通过JS/AJAX(Axios)发送它

如何适应JS

要与一起使用,请使用
auth
进行基本身份验证:

axios({
    method: 'get',
    url: 'https://example.com/pc_api/index.php/token',
    responseType: 'json', // default is json
    auth: {
        username: 'test',
        password: 'test'
    }
}).then(function(response) {
    console.log(response);
}).catch(function(error) {
    console.log(error);
});

检查

我认为这解决了您的问题:
axios({
    method: 'get',
    url: 'https://example.com/pc_api/index.php/token',
    responseType: 'json', // default is json
    auth: {
        username: 'test',
        password: 'test'
    }
}).then(function(response) {
    console.log(response);
}).catch(function(error) {
    console.log(error);
});