你如何使用jQuery调用需要基本身份验证的JSON Web服务? [英] How do you call a JSON web service, that requires basic authentication, using jQuery?

查看:58
本文介绍了你如何使用jQuery调用需要基本身份验证的JSON Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript方面有些新手,但我试图调用一个JSON Web服务,需要使用jQuery进行基本身份验证(或任何真正有效的方法)。

I am somewhat novice at javascript, but I am trying to call a JSON web service that require basic authentication using jQuery (or anything that would work really).

我无法在Google上找到任何真正的答案。我正在尝试做什么?

I've not been able to come up with any real answers on Google. Is what I am trying to do possible?

推荐答案

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

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.

这篇关于你如何使用jQuery调用需要基本身份验证的JSON Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆