Jquery 通过Ajax调用使用http基本身份验证
我需要联系服务器以使用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:
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');
}
})