#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.163.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)
MsgBox(0,1,StringInStr($sData, 'http://img1.cache.netease.com/img09/icon/icon.png')) ; ===> 會傳回1700
Else
MsgBox(48, "Error", "Site is experiencing problems.")
EndIf
; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
查找 http://img1.cache.netease.com/img09/icon/icon.png 會傳回 1700
沒有問題 |