Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 通过Ajax调用使用http基本身份验证_Jquery_Ajax_Http_Authentication_Http Headers - Fatal编程技术网

Jquery 通过Ajax调用使用http基本身份验证

Jquery 通过Ajax调用使用http基本身份验证,jquery,ajax,http,authentication,http-headers,Jquery,Ajax,Http,Authentication,Http Headers,我需要联系服务器以使用HTTP服务 使用https://example.com/service我得到了“基本身份验证”对话框 将URL更改为https://username:password@example.com/service很容易绕过这一点 尝试使用Ajax执行相同操作总是导致401未经授权,尽管: $.ajax({ url: 'https://username:password@example.com/service', // rest repeats type:

我需要联系服务器以使用HTTP服务

使用
https://example.com/service
我得到了“基本身份验证”对话框

将URL更改为
https://username:password@example.com/service
很容易绕过这一点

尝试使用Ajax执行相同操作总是导致
401未经授权
,尽管:

$.ajax({
    url: 'https://username:password@example.com/service',
    // rest repeats
    type: "GET",
    async: true,
    success: function(text) { alert('success'); },
    error: function (text) { alert('error') },
    complete: function(text) { alert('complete'); }
});

我自己也遇到过类似的情况。。 使用jsonp的诀窍是什么(呃):


马克拉普:我已经检查过这个问题了,但我仍然有401错误。你试过我链接的解决方案了吗?该解决方案中的第二个块是特定的?您确定使用了正确的凭据吗?请尝试在开发者控制台(chrome中的F12)中调试,并确保标题得到了sentI,因为我在这里遇到了相同的问题。似乎上面的解决方案对我不起作用。我收到了400个错误的请求
$.ajax({
    url: 'https://example.com/service',
    username: username,
    password: password,
    // snip repeat
});
$.ajax({
    url: 'https://example.com/service',
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", "Basic "
            + btoa(username + ":" + password));
    },
    // snip repeat
});
$.ajax({
        url: "https://localhost:8443/v1/accounts",
        type: 'GET',
        dataType: 'jsonp',
        beforeSend: function (xhr) {
            xhr.setRequestHeader('Authorization', 'Basic bHVpZ2lAZ21haWwuY29tOmFiYzEyMzQ1');
        }
    })