找回密码
 加入
搜索
查看: 5299|回复: 5

[网络通信] 用microsoft.xmlhttp对象,open不存在的url,send的时候出错[已解决]

  [复制链接]
发表于 2010-10-13 12:37:05 | 显示全部楼层 |阅读模式
本帖最后由 oneyicn 于 2010-10-13 15:08 编辑
先看代码
Dim $sUrl="http://www.baidus.com/"

        $oHTTP = ObjCreate("microsoft.xmlhttp")
        $aa=$oHTTP.Open("GET",$sUrl,False)
;~         ConsoleWrite($oHTTP.onreadystatechange & @CRLF);xmlhttp.readyState
        $oHTTP.Send("");发送
        $HTMLSource = $oHTTP.Responsetext 
        MsgBox(0,"",$HTMLSource)
如果url连接不上的时候,程序执行到Send()的时候,程序会动退出,并报错,搜索资料,也没有相关信息,请各位帮忙解决.
解决方法看3#

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-10-13 12:39:09 | 显示全部楼层
查阅帮助文档的“COM 出错处理”
 楼主| 发表于 2010-10-13 13:23:47 | 显示全部楼层
Dim $sUrl="http://www.baidusf.com/"
        $oMyError = ObjEvent("AutoIt.Error","MyErrFunc");加这行初始COM 对像句柄,这样就可以知道出错的原因了error handler        
        $oHTTP = ObjCreate("microsoft.xmlhttp")
        $aa=$oHTTP.Open("GET",$sUrl,False)
ConsoleWriteError(@error)
        $oHTTP.Send("");发送
        
Func MyErrFunc()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )            
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1    
    $g_eventerror = $err  ; to check for after this function returns
Endfunc
多谢afan版的指点..
发表于 2010-10-13 14:35:45 | 显示全部楼层
请修改标题后面的“如错解决[解决]”为“如何解决[已解决]”
规范标题关键字,便于搜索,利国利民~
发表于 2010-10-13 16:25:27 | 显示全部楼层
都这个时候啦,楼主就不要再执迷 XMLHTTP 这个老旧的东西啦,  Winhttp 是最好的选择。
发表于 2011-11-4 21:59:53 | 显示全部楼层
感谢指点~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-19 16:21 , Processed in 0.085951 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表