【问题标题】:AJAX Request with Password带密码的 AJAX 请求
【发布时间】:2017-11-25 14:00:45
【问题描述】:

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

如何适应JS?

$username = 'test';
$password = 'test';

$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'https://example.com/pc_api/index.php/token');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_handle, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

【问题讨论】:

标签: ajax ssl curl passwords axios


【解决方案1】:

要与axios 一起使用,请使用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);
});

查看request config params

【讨论】:

    猜你喜欢
    • 2011-04-29
    • 2014-02-11
    • 2020-08-17
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 2014-03-07
    相关资源
    最近更新 更多