Can anyone provide some insight into how i'd go about decompressing an XML response in classic ASP. We've been handed some code and asked to get it working:
Set oXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
URL = HttpServer + re_domain + ".do;jsessionid=" + ue_session + "?" + data
oXMLHttp.setTimeouts 5000, 60000, 1200000, 1200000
oXMLHttp.open "GET", URL, false
oXMLHttp.setRequestHeader "Accept-Encoding", "gzip"
oXMLHttp.send()
if oXMLHttp.status = 200 Then
if oXMLHttp.responseText = "" then
htmlrequest_get = "Empty Response from Server"
else
htmlrequest_get = oXMLHttp.responseText
end if
else
...
Apparently now that the response is compressed using gzip, we have to un-compress the XML response before we can start to work with the data.
How should i go about this?
ServerXMLHTTP does not support compression.
You may however try to use a GZip component:
http://www.vclcomponents.com/ASP/File_Manipulation/File_Management/GZip_Component-info.html
Oooops, didn't check the date of the questions! :)
Related
I am sending an HTTP POST to an API with a json request to download a zip file. The response contains the zip file in the responseBody. I have verified this sequence in Postman with the responsebody containing the zip file.
I am attempting to save the zip file from the http response body to a local file doing the following in VBScript:
Sub Download_Study_Bundle
URL = myURL
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0"
objHTTP.setRequestHeader "Authorization", "Basic base64encodeduserandpassword"
objHTTP.setRequestHeader "Content-Type", "application/json; charset=UTF-8"
objHTTP.setRequestHeader "CharSet", "charset=UTF-8"
objHTTP.setRequestHeader "Accept", "application/json"
json = myjson
objHTTP.send (json)
dim bStrm: Set bStrm = createobject("Adodb.Stream")
with bStrm
.type = 1 '//binary
.open
.write objHTTP.responseBody
.savetofile myFile, 2 '//overwrite
end with
end sub
I get an error on line : ".write objHTTP.responseBody"
that states:
"Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."
I can see in my logs that I get a proper 200 response with something in ResponseBody. I am unable to figure out why the responseBody cannot be written as a binary stream to the ADODB object. Any help is appreciated.
EDIT: a screenshot of the same json sent in postman produces the raw zip file in the response body:
http response
I'm making a call to an external API. The data it returns, annoyingly, is in the header (the text response is empty).
How do I access the header of the response?
This is what I'm trying:
Dim httpRequest, postResponse
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", "http://www.api.com", False, "un", "pw"
httpRequest.SetRequestHeader "Content-Type", "application/json"
httpRequest.setRequestHeader "Content-Length", len(jsondata)
httpRequest.Send data
if httpRequest.status = 200 then
response.write httpRequest.getResponseHeader
response.write httpRequest.ResponseText
end if
Set httpRequest = nothing
But it gives me:
msxml3.dll error '80072f76'
The requested header was not found
And a bonus question: I just noticed the "XML" part of "MSXML2.ServerXMLHTTP" - am I using the right protocol? It's always worked for straight posts and gets until now.
You need to specify the name of the response header you want to retrieve:
response.write httpRequest.getResponseHeader("SomeHeaderName")
There's no just one response header. There could be many. You have the standard response headers such as Content-Type and you could also have custom headers.
And a bonus question: I just noticed the "XML" part of
"MSXML2.ServerXMLHTTP" - am I using the right protocol?
Yes, absolutely, that's the correct COM object to be used from a classic ASP application to send HTTP requests.
I would like to use the Pingdom REST API from Classic ASP, but the following code:-
' setup the URL
baseUrl = "https://api.pingdom.com/api/2.0/checks"
' setup the request and authorization
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", baseUrl, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "userpwd", "aaaaaaaaaaaaaaaaaaaaaaa:bbbbbbbbbbb"
http.setRequestHeader "App-Key", "ccccccccccccccccccccccccccccccc"
' send the HTTP data
http.send
gives me the error:-
{"error":{"statuscode":401,"statusdesc":"Unauthorized","errormessage":"User credentials missing"}}
so my authentication isnt being passed correctly, and it looks like it should NOT be passed in the requestheader, but I'm not sure how it should be done.
Thanks
Thanks for Alex K. and for the benefit of others, the correct syntax is:-
' setup the URL
baseUrl = "https://api.pingdom.com/api/2.0/checks"
Response.Write fullUrl
' setup the request and authorization
Set http = Server.CreateObject("MSXML2.ServerXMLHTTP")
http.open "GET", baseUrl, False, "emailaddress", "password"
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.setRequestHeader "App-Key", "keykeykeykeykeykeykeykeykeykey"
' send the HTTP data
http.send
:-)
https://api.pingdom.com/api/2.0/checks is using Basic Authentication so you need to pass your credentials in the .open call.
I am trying to build an application where i can upload files to youtube.
I have gotten OAuth working, and Youtube is returning a session!
The problem i am having is, youtube requires i make an XMLHTTP POST to get a url where i can upload through my web page.
I have no idea how to make an XMLHTTP Post with the extra parameters youtube requires.
They have code samples in PHP and .net both of which i dont understand yet :(
This is where i am stuck:
http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html#Sending_a_Browser_Upload_API_Request
I dont know how to Format an xml http command to have all those variables youtube wants.
Please help...
here is what they want..
POST /action/GetUploadToken HTTP/1.1
Host: gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
Here is the code i have now:
I think i need the Headers?
When i post it i get a response of not authorized.
I also tried to create an old html and try that but it does not work...
Have no idea how those paramenters are sent:
Here is what i got
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
URLString = "http://gdata.youtube.com/action/GetUploadToken"
SendString = ""
SendString = SendString & "Authorization: AuthSub token=" & token
xmlHttp.open "POST", URLString & "?" & SendString
xmlHttp.setRequestHeader "Host:", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization: AuthSub token=", token
xmlHttp.setRequestHeader "GData-Version:", "2"
xmlHttp.setRequestHeader "Content-Length:", "<content_length>"
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-"
xmlHttp.send SendString
If xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
Response.Write "<BR><BR><BR>Error Occured: " & xmlHttp.statusText
Else
' ReturnData = Replace(xmlHttp.responseText, "&", ",")
Response.Write "<BR><BR><BR>WENT GOOD?<BR>" & xmlHttp.responseText
End If
First, setRequestHeader doesn't take a colon. It should just be
xmlHttp.setRequestHeader "Host", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization", "AuthSub token=" & token
xmlHttp.setRequestHeader "GData-Version", "2"
xmlHttp.setRequestHeader "Content-Length", "<content_length>" <-- THIS IS IMPORTANT!
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-8"
Next, are you sending the correct content-length? This NEEDS to be accurate.
I assume the missing "8" from your Content-Type header at the end was a typo.
Finally, you NEED to install Fiddler right away and make your life simpler.
I am sending an XML content via HTTP Post from Access VBA to Web Methods, using XMLHTTP object in MSXML. Here is the Code.
Dim objXmlHttp As Object
Set objXmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
objXmlHttp.Open "POST", webServicePath, False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
Dim Response As String
objXmlHttp.send wrt.output
'OK status
If objXmlHttp.Status = 200 Then
Response = objXmlHttp.responseText
End If
Set objXmlHttp = Nothing
I am getting the XML with "<" and ">" instead of < and >.
If I try to do URL encoding, everything is received as ASCII text in the Recipient side.
Can you please guide what I need to do to get the valid XML format.
You need to set the content-type correctly, try this instead:
objXmlHttp.setRequestHeader "Content-Type", "text/xml; charset=""utf-8"""