通过msxml2.ServerXMLHTTP提供认证信息 [英] Providing authentication info via msxml2.ServerXMLHTTP

查看:1824
本文介绍了通过msxml2.ServerXMLHTTP提供认证信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用经典ASP,并试图使用JustGiving API。

I am using Classic ASP and trying to use the JustGiving API.

我想用它来显示募集的总金额,而我的捐赠页面上收到的捐款总额,在我的网站。

I'd like to use it to display the total amount raised, and total donations received on my donation page, on my website.

我可以看到,通过信息可用:
https://api.justgiving.com/docs/resources/v1/Account/Retrieve

I can see that info is available via: https://api.justgiving.com/docs/resources/v1/Account/Retrieve

<%
vurl = "http://api.justgiving.com/---myIDhere---/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False
http.Send

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then
        var_totalDonated = ap(totalDonated(0).Text)
        response.write var_totalDonated
    End If

Next
%>

不过,页面超时,当我访问它。

However, the page times out when I access it.

我想这是因为我需要提供一些认证信息为这里详细:
https://api.justgiving.com/docs/usage#protectedResources

I think it's because I need to provide some authentication information as detailed here: https://api.justgiving.com/docs/usage#protectedResources

所以我得到了验证信息。

So I got that authentication info.

但我不知道如何发送它的API,以便它可以验证我作为一个用户,并提供信息。

But I have no idea how to "send" it to the API, so that it can authenticate me as a user and provide the info.

它还提到通过上面这个链接提供的头信息(我不能发布的链接,因为我没有足够的声望),但与#contentTypes URL的末尾替换#protectedResources。

It also mentions providing info on the header via the link above this one (I can't post the link as I don't have enough reputation), but replace #protectedResources at the end of the URL with #contentTypes.

对不起 - 我我也缺少该侧的东西。

I'm sorry - am I also missing something on that side?

我很抱歉,如果我问愚蠢的问题,但在API文档的信息呈现在用户的智能部分某种程度,我没有很多呢!

I'm sorry if I'm asking silly questions, but the info on the API docs assumes some level of intelligence on the part of the user, and I don't have a lot of it!

任何意见多少AP preciated。

Any advice much appreciated.

感谢

感谢John您的回复。

Thanks to John for your reply.

,我改变了code为:

Based on that, I changed the code to:

<%
vurl = "https://api.justgiving.com/API_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, "username", "pwd"
http.setTimeouts 5000, 5000, 10000, 10000 ''ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
http.Send

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then 
        var_totalDonated = (var_totalDonated(0).Text)
        response.write var_totalDonated
    End If

Next
%>

可惜还是页面超时。

But unfortunately the page still times out.

我也通过检查:
groups.google.com/forum /#!话题/ justgiving-API / Xhz5Fkxuy1s

I'm checking also via: groups.google.com/forum/#!topic/justgiving-api/Xhz5Fkxuy1s

但没有答案为止。

再次感谢

<%

Sub debug( varName )
    Dim varValue
    varValue = Eval( varName )
    response.write "<p style='margin:10px; border-bottom:2px solid #ccc;border-top:1px solid #eaeaea;background-color:white;padding:10px;color:red;text-align:left;'><strong>" & varName & "</strong>: " & varvalue & "</p>" & vbcrlf & vbcrlf
End Sub

vurl = "https://api.justgiving.com/AP_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, username, password
http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic AUTH_STRING"
http.Send

Response.ContentType = "application/xml"

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then 
        var_totalDonated = ap(var_totalDonated(0).Text)
        debug "var_totalDonated"
    End If

    Set var_totalRaised = item.getElementsByTagName("totalRaised")
    If NOT (var_totalRaised IS Nothing) Then 
        var_totalRaised = ap(var_totalRaised(0).Text)
        debug "var_totalRaised"
    End If

    Set var_totalGiftAid = item.getElementsByTagName("totalGiftAid")
    If NOT (var_totalGiftAid IS Nothing) Then 
        var_totalGiftAid = ap(var_totalGiftAid(0).Text)
        debug "var_totalGiftAid"
    End If

Next
%>

previously我用的是:

Previously I was using:

vurl = "https://api.justgiving.com/AP_KEY/v1/account"

但是,当我把它改为HTTPS它的工作。

But when I changed it to https it worked.

我想我已经试过了previously,但显然不是。

I thought I had tried that previously, but obviously not.

再次感谢约翰,我真的AP preciate您的帮助!

Thanks again to John, I really appreciate your help!

推荐答案

尝试

http.Open "GET", vurl, False, "yourusername", "yourpassword"

我不知道如果这个工程上justgiving,但它与必应API确实

I don't know if this works on justgiving, but it does with the Bing API

此外,这个问题可能是相关
XMLHTTP请求基本身份验证问题

Also, this question may be relevant XmlHttp Request Basic Authentication Issue

编辑 - 使用Response.ContentType和Msxml2.ServerXMLHTTP.6.0

Edit - using Response.ContentType and Msxml2.ServerXMLHTTP.6.0

vurl = "https://api.justgiving.com/API_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP.6.0")
http.Open "GET", vurl, False, "username", "pwd"
http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
http.Send

Response.ContentType = "application/xml"    

Set items = http.responseXML.getElementsByTagName("account")

这篇关于通过msxml2.ServerXMLHTTP提供认证信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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