本帖最后由 fuinei 于 2012-3-30 11:12 编辑
回复 28# calora88
谢谢指导,代码返回访问页面的内容,该方法仍需判断返回内容才能确定当前帐号在PC上能否访问Internet,使用以下代码时遇到不能准确判断结果,不知道是否由于内容太多导致变量$sData无法存放所有的内容导致的呢?#include "WinHttp.au3"
Opt("MustDeclareVars", 1)
; Initialize
Global $hOpen = _WinHttpOpen()
If @error Then
MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
Exit 1
EndIf
; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen, "www.baidu.com") ; <- yours here
If @error Then
MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
_WinHttpCloseHandle($hOpen)
Exit 2
EndIf
; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect)
If @error Then
MsgBox(48, "Error", "Error creating an HTTP request handle.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 3
EndIf
; Send it
_WinHttpSendRequest($hRequest)
If @error Then
MsgBox(48, "Error", "Error sending specified request.")
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 4
EndIf
; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
MsgBox(48, "Error", "Error waiting for the response from the server.")
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 5
EndIf
; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
; Read
While 1
$sChunk = _WinHttpReadData($hRequest)
If @error Then ExitLoop
$sData &= $sChunk
WEnd
; ConsoleWrite($sData & @CRLF) ; print to console
;MsgBox(0,1,$sData)
If StringInStr($sData,"Note: Please have your identity authenticated before accessing the Internet。",1) > 0 Then
MsgBox(48,"Error","请登陆代理服务器")
ElseIf StringInStr($sData,"http://192.168.1.254/disable/disable.htm",1) >0 then
MsgBox(48,"Error","当前帐号不允许访问Internet")
Else
MsgBox(0,"Info","当前帐号可以访问Internet")
EndIf
Else
MsgBox(48, "Error", "Site is experiencing problems.")
EndIf
; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
|