jQuery没有为基本身份验证发送标头

时间:2015-08-14 21:36:37

标签: jquery ajax limejs

我已经尝试了我在stackoverflow上看到的每个例子,但我仍然无法获得jquery包含授权。我是用户 jQuery 1.11.3 。这是我的ajax电话

var headers = "Basic "+username+":"+password;
var data = $.ajax({
        type: "GET",
        url: "https://55.55.55.55:6025/users",
        crossDomain: true,
        dataType: 'jsonp',
        beforeSend : function(xhr) {
          xhr.setRequestHeader("Authorization", headers);
        },
        xhrFields: {
          withCredentials: 'true'
        },
        processData: 'false'
})
data.done(function (result) {
    console.log(result);
})
data.fail(function (result) {
    console.log(result);
});

我也试过这个:

var data = $.ajax({
    type: "GET",
    url: "https://104.236.169.12:6025/users",
    crossDomain: true,
    dataType: 'jsonp',
    username: creds[0],
    password: creds[1]
})

为什么这不包括请求标头中的授权字段?

我也在使用limejs。因此,如果内部存在某种我没有得到的CORS功能,请有人指出这一点吗?

修改

我发现这种方法似乎有效:

var data = $.ajax({
    type: "GET",
    url: "https://user@email.edu:pass@104.236.169.12:6025/users",
    dataType: 'jsonp'
})

但它在http请求中以纯文本形式发送凭据。这是一种安全的方法吗?

0 个答案:

没有答案