gpt4 book ai didi

jquery - 使用 jquery 和 ajax 发送授权 header

转载 作者:行者123 更新时间:2023-12-03 22:59:53 26 4
gpt4 key购买 nike

我在 stackoverflow 上查看了以下问题,但我想做的事情却没有运气。

Ajax Authorization Request headers fails again and again

jQuery Ajax Unauthorized 401 Error

Sending credentials with cross-domain posts?

这是我目前拥有的代码:

    $(document).ready(function() {
$.ajax({
url: 'http://sample.domain.com/script.php?name1=value1&jsonp=?',
type: 'GET',
dataType: 'json',
contentType: "application/json",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authentication", "Basic ZnJvbWFwcGx********uOnRoM24zcmQ1UmgzcjM=") //Some characters have been replaced for security but this is a true BASE64 of "username:password"
},
success: function(data){
alert(data);
}
});
});


</script>

我的子域受 .htpasswd 文件的密码保护。使用 Base64 编码中使用的用户名/密码组合,该网站的登录对我来说效果很好。

我在与网址所在的域不同的域上运行此脚本,这就是为什么我有 jsonp=?在网址中

我从浏览器控制台得到的响应是: GET http://sample.domain.com/script.php?name1=value1&jsonp=jsonp1334177732136 401(需要授权)

最佳答案

header 名称为Authorization,并且您正在发送“Authentication

例如

Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtBmU=

关于jquery - 使用 jquery 和 ajax 发送授权 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10113911/

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