gpt4 book ai didi

javascript - 使用 Ajax 弹出窗口进行基本身份验证登录?

转载 作者:行者123 更新时间:2023-12-03 04:49:36 25 4
gpt4 key购买 nike

在这里,我尝试访问 reed.co.uk Rest webapi 来获取所有相关作业,当我调用 URL 时,即使我传递用户名和密码,它也会显示此弹出窗口。这是我收到的警报消息:

http://www.reed.co.uk is requesting your username and password. WARNING: Your password will not be sent to the website you are currently visiting!

enter image description here

请帮助我哪里做错了。

这是 Ajax 代码

var username = "xxxxx xxxxxxxxxxxxxxx";
var password = "";
function getAuthorizationHeader(username, password) {
var authType;
var up = $.base64.encode(username + ":" + password);
authType = "Basic " + up;
console.log(authType);
return authType;
};

$.ajax({
type: "GET",
url: "http://www.reed.co.uk/api/1.0/search?keywords=Software Engineer&locationName=London&distanceFromLocation=50",
dataType: 'jsonp',
async: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', getAuthorizationHeader(username, password));
},
success: function (response) {
console.log(response);
}
});

我也尝试像这样传递授权 header ,但仍然弹出窗口

headers: {
'Authorization': getAuthorizationHeader(username, password)
},

最佳答案

看起来它正在等待基本身份验证。因此您需要在 url 处提供它。

例如:

$.ajax({
type: "GET",
url: "http://"+username+":"+password+"@www.reed.co.uk/api/1.0/search?keywords=Software Engineer&locationName=London&distanceFromLocation=50",
dataType: 'jsonp',
async: false,
success: function (response) {
console.log(response);
}});

关于javascript - 使用 Ajax 弹出窗口进行基本身份验证登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42718104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com