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

前端之家收集整理的这篇文章主要介绍了api – 通过msxml2.ServerXMLHTTP提供身份验证信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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
%>

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

我想这是因为我需要提供一些身份验证信息,如下所示:
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",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
%>

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

我也通过以下方式检查:
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",username,password
http.setTimeouts 5000,10000 'ms - resolve,"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
%>

以前我用过:

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

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

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

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

解决方法

尝试
http.Open "GET","yourusername","yourpassword"

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

此外,这个问题可能是相关的
XmlHttp Request Basic Authentication Issue

编辑 – 使用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",receive'
http.setRequestHeader "Authorization","Basic MY_AUTH_STRING"
http.Send

Response.ContentType = "application/xml"    

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

等等

原文链接:https://www.f2er.com/aspnet/246687.html

猜你在找的asp.Net相关文章