2014-09-13 107 views
1

在執行以下vbs代碼時出現錯誤 - 800A01AD。WinHTTPRequest:ActiveX組件無法創建對象

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

它將引發 'ActiveX組件不能創建對象'。我在我的機器上註冊了WinHTTP.dll。

回答

1

如果這是一個真正的複製/粘貼,那麼你必須在創建對象一個錯字(「WinHTTP的。WinHTPPRequest .5.1」)

0

只要給一個嘗試與MSXML2.ServerXMLHTTP並告訴我,如果你的作品或不是?

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