我在 javascript 方面有点新手,但我正在尝试调用一个需要使用 jQuery(或任何真正有效的东西)进行基本身份验证的 JSON Web 服务。
我无法在 Google 上找到任何真正的答案。我正在尝试做的事情可能吗?
最佳答案
您需要设置适当的请求 header 以传递凭据。例如参见 here .
$.getJSON({
'url': 'http://host.com/action/',
'otherSettings': 'othervalues',
'beforeSend': function(xhr) {
//May need to use "Authorization" instead
xhr.setRequestHeader("Authentication",
"Basic " + encodeBase64(username + ":" + password)
},
success: function(result) {
alert('done');
}
});
仅供引用,我在 Google 中搜索了 jquery post with basic auth
,这是第一个链接。
关于javascript - 如何使用 jQuery 调用需要基本身份验证的 JSON Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6025764/