我在 javascript 方面有点新手,但我正在尝试调用一个 JSON Web 服务,该服务需要使用 jQuery (或任何真正有效的东西)进行基本身份验证。
我在谷歌上找不到任何真正的答案。我想做的事情可能吗?
您将需要设置适当的请求标头来传递凭据。例如参见here http://dothow.blogspot.com/2009/05/http-basic-authentication-with-jquery.html.
$.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');
}
});
仅供参考,我在谷歌上搜索了jquery post with basic auth
这是第一个链接。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)