【问题标题】:WinHTTPRequest : ActiveX component can't create objectWinHTTPRequest:ActiveX 组件无法创建对象
【发布时间】:2014-11-07 15:29:58
【问题描述】:

执行以下 vbs 代码时出现错误 - 800A01AD。

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。

【问题讨论】:

    标签: vbscript winhttprequest


    【解决方案1】:

    如果这是真正的复制/粘贴,那么您在 CreateObject("WinHTTP.WinHTPPRequest.5.1") 中有错字

    【讨论】:

      【解决方案2】:

      试试 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
      

      【讨论】:

        猜你喜欢
        • 2010-12-25
        • 2018-01-22
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 2012-07-10
        相关资源
        最近更新 更多