通过msxml2.ServerXMLHTTP提供身份验证信息

6 api asp-classic

我正在使用Classic ASP并尝试使用JustGiving API.

我想用它在我的网站上显示我捐赠页面上收到的总金额和捐款总额.

我可以通过以下网址查看该信息: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
%>
Run Code Online (Sandbox Code Playgroud)

但是,当我访问它时页面超时.

我认为这是因为我需要提供一些身份验证信息,如下所示:https: //api.justgiving.com/docs/usage#protectedResources

所以我得到了身份验证信息.

但我不知道如何将它"发送"到API,以便它可以作为用户验证我并提供信息.

它还提到通过上面的链接提供标题信息(我不能发布链接,因为我没有足够的声誉),但用#contentTypes替换URL末尾的#protectedResources.

对不起 - 我还缺少那边的东西吗?

如果我问的是愚蠢的问题,我很抱歉,但是关于API文档的信息假定用户方面有一定程度的智能,而且我没有太多的信息!

任何建议都非常感谢.

谢谢


感谢John的回复.

基于此,我将代码更改为:

<%
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
%>
Run Code Online (Sandbox Code Playgroud)

但不幸的是,该页面仍然超时.

我还要查看: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
%>
Run Code Online (Sandbox Code Playgroud)

以前我用过:

vurl = "https://api.justgiving.com/AP_KEY/v1/account"
Run Code Online (Sandbox Code Playgroud)

但是,当我将其更改为https时,它起作用了.

我以为我之前尝试过,但显然不是.

再次感谢John,非常感谢您的帮助!

Joh*_*ohn 13

尝试

http.Open "GET", vurl, False, "yourusername", "yourpassword"
Run Code Online (Sandbox Code Playgroud)

我不知道这是否适用于宽容,但它与Bing API有关

此外,这个问题可能与 XmlHttp请求基本认证问题有关

编辑 - 使用Response.ContentType和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")
Run Code Online (Sandbox Code Playgroud)

等等