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

查看:53
本文介绍了通过 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.

它还提到通过此链接上方的链接提供有关标题的信息(我无法发布链接,因为我没有足够的声誉),但将 URL 末尾的 #protectedResources 替换为 #contentTypes.

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!

非常感谢任何建议.

谢谢

感谢约翰的回复.

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

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/#!topic/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
%>

以前我使用的是:

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

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

But when I changed it to https it worked.

我以为我以前尝试过,但显然没有.

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

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

Thanks again to John, I really appreciate your help!

推荐答案

尝试

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

我不知道这是否适用于 justgiving,但它适用于 Bing 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天全站免登陆