我正在尝试使用MS Access中的vba从Socrata站点中提取一些数据。 但是,我返回了500状态。
我要发送给函数的URL是从socrata网站的oData部分复制的。
' Given a URL, reads an OData feed or entry into an XML document.
Function ODataReadUrl(ByVal strUrl As String) As MSXML2.DOMDocument60
Dim objXmlHttp As MSXML2.XMLHTTP60
Dim objResult As MSXML2.DOMDocument60
Dim strText As String
Dim strUser As String
strUser = EncodeBase64("REDACTED")
Dim strPw As String
strPw = EncodeBase64("REDACTED*")
Dim strToken As String
strToken = EncodeBase64(REDACTED)
' Make a request for the URL.
Set objXmlHttp = New MSXML2.XMLHTTP
objXmlHttp.Open "GET", strUrl, False
objXmlHttp.setRequestHeader "Authorization", "Basic " + strUser + ":" + strPw
objXmlHttp.setRequestHeader "X-App-Token:", strToken
objXmlHttp.setRequestHeader "X-Socrata-RequestId", "B93C4239-7F30-47CD-BC73-8F79F81096A2"
objXmlHttp.send
If objXmlHttp.Status <> 200 Then
Err.Raise ODataCannotReadUrlError, "ODataReadUrl", "Unable to get '" & strUrl & "' - status code: " & objXmlHttp.Status
End If
' Get the result as text.
strText = objXmlHttp.responseText
Set objXmlHttp = Nothing
' Create a document from the text.
Set objResult = New MSXML2.DOMDocument60
objResult.LoadXML strText
If objResult.parseError.ErrorCode <> 0 Then
Err.Raise ODataParseError, "ODataReadUrl", "Unable to load '" & strUrl & "' - " & objResult.parseError.reason
End If
Set ODataReadUrl = objResult
End Function