我的目标是建立一个访问者可点击的链接,然后通过基本身份验证重定向并登录到网站。我们目前在一些非我们的网页but embedded credentials are no longer supported in Chrome上使用嵌入式凭证。我一直在研究替代传递凭据的URL(即https://user:[email protected]
),至今还没有找到一个解决方案,它比好以下几点:Chrome浏览器中嵌入凭据的替代方法可用于指向第三方网站的链接?
var url = 'https://www.third-party-website.com';
var username = 'my-username';
var password = 'my-password';
var encodedAuth = window.btoa(username + ':' + password);
$.ajax({
type: 'GET',
url: url,
xhrFields: {
withCredentials: true,
},
headers: {
"Authorization": "Basic " + encodedAuth
},
complete: function (result) {
window.location.href = url;
},
error: function (req, status, error) {
console.log(error);
}
});
使我有以下错误:
XMLHttpRequest cannot load https://www.third-party-website.com . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://my-website.com ' is therefore not allowed access.
Based on this SO thread,我想我需要访问第三方的服务器来设置其Access-Control-Allow-Origin
以允许我的域名。如果我无法更改第三方服务器上的标题,是否还有其他替代方案?或者我的AJAX请求格式不正确?
你的AJAX是张贴到您代理的用户名+密码正确配置。使用代理可以实现你需要的东西。其他网站的Cookie可能会有问题 – charlietfl