Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XMLHTTP File download script not working on URLs without extension

Status
Not open for further replies.

tektipsblitz

IS-IT--Management
Nov 3, 2011
18
CA
I have been working with a script to automatically download an XML from Yahoo, using the YQL REST API.

The problem I have is that the URL does not have a '.xml' or any other extension in it....which is blowing up the script.

The URL is followed by the querystring. The script will only function when the extension is mentioned in the URL... e.g. it would work on ... but not
Anybody have any ideas? I've spent days on this and got no where :(



function download(sFileURL, sLocation)

'create xmlhttp object
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

'get the remote file
objXMLHTTP.open "GET", sFileURL, false
objXMLHTTP.SetRequestHeader "Content-type", "text/html"


'send the request
objXMLHTTP.send()

'wait until the data has downloaded successfully
do until objXMLHTTP.Status = 200 : wscript.sleep(1000) : loop

'if the data has downloaded sucessfully
If objXMLHTTP.Status = 200 Then

'create binary stream object
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open

'adTypeBinary
objADOStream.Type = 1
objADOStream.Write objXMLHTTP.ResponseBody

'Set the stream position to the start
objADOStream.Position = 0

'create file system object to allow the script to check for an existing file
Set objFSO = Createobject("Scripting.FileSystemObject")

'check if the file exists, if it exists then delete it
If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation

'destroy file system object
Set objFSO = Nothing

'save the ado stream to a file
objADOStream.SaveToFile sLocation

'close the ado stream
objADOStream.Close

'destroy the ado stream object
Set objADOStream = Nothing

'end object downloaded successfully
End if



'destroy xml http object
Set objXMLHTTP = Nothing

End function

download " "c:\1.xml"
 
Sounds like the server is running IIS which has "issues" with POST and GET verbs when a request is made to a URI that does not have document name appended.

It is apparently due to the way that IIS handles the internal redirect to the default document 'search'

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top