I am trying to read open (WinhttpReq) an xml file and save it to a directory in the root of c:\. The code is pretty straight forward but I think the code is either stepping through the code too quickly or the website is taking longer to honor the request
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
' Use the URL of the text file you wish to retrieve:
WinHttpReq.Open "GET", "http://api.theweatherchannel.com/data/trupoint_cc/02472?doctype=xml&units=s&apikey=_MyKey_&country=US&locale=en_US", False
If (WinHttpReq.Status = 200) Then
sTemp = WinHttpReq.ResponseText
' Replace any carriage returns and linefeeds with spaces
sTemp = Replace(sTemp, vbCr, " ")
sTemp = Replace(sTemp, vbLf, " ")
WebText = sTemp
'Create the 'weather' file
Set objFile = objFSO.OpenTextFile("C:\myWeather.txt", 8, True)
Set objFile = Noth
' Failed -- return empty string
WebText = ""
When I run the code it does not return an error but the file does not appear in the folder.
Is there something that I'm missing that I should be adding to allow for the host to respond and send the file. Should I put up a prompt that would expose (or post) the xml file into a dialogue box to verify the code has actually read or parsed the file?