I created the following code:
URL = "https://github.com/index.html"
Set xHttp = CreateObject("MSXML2.ServerXMLHTTP")
xHttp.Open "GET", URL, False
xHttp.setOption 2, 13056
xHttp.Send()
Executing 'xHttp.Send', I get an msxml3 error 0x80090326, "The message received was unexpected or badly formatted".
For other secure URLs the above code works. Not for this one! However, the open source utility 'wget' can access this URL uisng the '--no-check-certificate' switch. Also, web browsers can access this URL. What is needed in VBScript to be able to succeed?
Try this code :
Option Explicit
Dim URL,Save2File
URL = "https://github.com/index.html"
Save2File = "index_github.txt"
Call GetData(URL,Save2File)
'**********************************************************************************************
Sub GetData(URL,Save2File)
Dim File,BS,ws
On Error Resume Next
Set File = CreateObject("MSXML2.ServerXMLHTTP")
File.Open "GET",URL, False
'This is IE 8 headers
File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
File.Send
If err.number <> 0 then
line =""
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error getting file"
Line = Line & vbcrlf & "=================="
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description
Line = Line & vbcrlf & "Source " & err.source
Line = Line & vbcrlf & ""
Line = Line & vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
Line = Line & vbcrlf & File.getAllResponseHeaders
wscript.echo Line
Err.clear
wscript.quit
End If
Set BS = CreateObject("ADODB.Stream")
Set ws = CreateObject("wscript.Shell")
BS.type = 1
BS.open
BS.Write File.ResponseBody
BS.SaveToFile Save2File, 2
End Sub
'**********************************************************************************************
User contributions licensed under CC BY-SA 3.0