ping 最好还加个 InetGetInfo 候补…… ping通直接过,ping不通就用InetGetInfo上
afan 发表于 2010-4-16 00:46
谢谢afan大大,这样么?Func _XmlHttp($URL, $Timeouts = 5000, $SleepTime = 1000) ;页面下载
;超时返回 "error",否则返回ResponseBody
$Host_Test = StringRegExp($URL, "http://(.*?)/", 3)
If Not @error Then
$Host = $Host_Test[0]
Else
$Host = StringReplace($URL, "http://", "")
EndIf ;获取主机名
If Ping($Host, $Timeouts) <=0 Then
$InetGet_Test = InetGet($URL, "InetGet.tmp", 1, 1)
Sleep($SleepTime)
If InetGetInfo($InetGet_Test, 0) = 0 Then
InetClose($InetGet_Test)
Return "error"
Else
InetClose($InetGet_Test)
FileDelete("InetGet.tmp")
EndIf
EndIf ;检测是否能连上
$oHTTP = ObjCreate("Microsoft.XMLHttp")
$oHTTP.Open ( "GET" , $URL , False )
$oHTTP.SetRequestHeader("Referer", "http://"&$Host&"/")
$oHTTP.SetRequestHeader("Accept-Language", "zh-cn")
$oHTTP.SetRequestHeader("Connection", "Keep-Alive");数据传递完并不立即关闭连接
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");表示客户端提交给服务器文本内容的编码方式
$oHTTP.SetRequestHeader("Cache-Control", "no-cache");返回消息中的Cache用于指定网页缓存
$oHTTP.Send ()
$oReturnWebS = BinaryToString ( $oHTTP.ResponseBody )
Return $oReturnWebS
$oHTTP.Nothing
EndFunc
|