简体   繁体   中英

WinHTTPRequest : ActiveX component can't create object

I am getting error - 800A01AD while executing the following vbs code.

strURL = "http://maps.yahoo.com/maps_result.php?q1=newyork"
Set myRequest = CreateObject("WinHTTP.WinHTPPRequest.5.1")
myRequest.Open "GET", strURL
myRequest.Send
msgbox myRequest.ResponseText

It throws 'ActiveX component can't create object'. I have WinHTTP.dll registered on my machine.

如果这是真正的复制/粘贴,则您在CreateObject(“ WinHTPPRequest .5.1”)中有错字

Just give a try with MSXML2.ServerXMLHTTP and tell me if it works for you or not ?

On Error Resume Next
 Set File = WScript.CreateObject("MSXML2.ServerXMLHTTP")
 File.Open "GET", "http://maps.yahoo.com/maps_result.php?q1=newyork", 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

On Error Goto 0

 Set BS = CreateObject("ADODB.Stream")
 BS.type = 1
 BS.open
 BS.Write File.ResponseBody
 BS.SaveToFile "test.txt", 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM