找回密码
 加入
搜索
楼主: fuinei

[网络通信] [已解决]判断PC能否访问Internet

 火.. [复制链接]
 楼主| 发表于 2012-3-30 16:09:22 | 显示全部楼层
回复 30# calora88
163首页才300多K,如果变量可以存放大量的数据难道路是StringInStr查找字符串时对字符串的大小有要求??
发表于 2012-3-30 18:01:02 | 显示全部楼层
#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
沒有問題
 楼主| 发表于 2012-3-31 08:26:13 | 显示全部楼层
回复 32# calora88

问题解决,昨天是我大意了,原来winhttp对中文的支持不好,部分字符会变乱码,修改判断条件后问题解决,谢谢!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-3-31 22:06:25 | 显示全部楼层
不错的方法,学习了
发表于 2012-4-2 14:27:56 | 显示全部楼层
有很多方法的。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 01:23 , Processed in 0.071774 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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