且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

你如何使用jQuery调用需要基本身份验证的JSON Web服务?

更新时间:2023-09-13 15:32:46

您需要设置相应的请求标头以传递凭据。例如,请参阅此处

You will need to set the appropriate request header to pass the credentials. For example see 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 ,这是第一个链接。

FYI I searched Google for jquery post with basic auth and this was the first link.