我创建了以下代码:
URL = "https://github.com/index.html"
Set xHttp = CreateObject("MSXML2.ServerXMLHTTP")
xHttp.Open "GET", URL, False
xHttp.setOption 2, 13056
xHttp.Send()
执行' xHttp.Send',我收到msxml3错误0x80090326,"收到的邮件意外或格式错误"。
对于其他安全URL,上述代码可以正常工作。不适合这个!但是,开源实用程序' wget'可以使用' - no-check-certificate'来访问此URL。开关。此外,Web浏览器可以访问此URL。 VBScript需要什么才能成功?
答案 0 :(得分:0)
试试这段代码:
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
'**********************************************************************************************