Afan老大,_WinHttpReadData的问题?
汉化版中的_winhttpreaddata()例子中怎么看不到_winhttpreaddata()的身影?测试了代码,无反应,定义和删除了没有用到的变量,运行后提示: _WinHttpSendRequest($hRequest)发生错误?#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#Include <WinHttp.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $iMemo
Global $sTarget
_Main()
Func _Main()
; 创建界面
GUICreate("HTTP Status", 800, 600)
; 创建memo控件
$iMemo = GUICtrlCreateEdit("", 2, 2, 796, 596, $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; 初始化并获取会话句柄
Global $hOpen = _WinHttpOpen()
If @error Then
MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
Exit 1
EndIf
; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, "www.sohu.com")
If @error Then
MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
_WinHttpCloseHandle($hOpen)
Exit 2
EndIf
; 创建请求
Global $hRequest = _WinHttpOpenRequest($hConnect, Default, $sTarget)
If @error Then
MsgBox(48, "Error", "Error creating an HTTP request handle.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 3
EndIf
; 发送请求
_WinHttpSendRequest($hRequest)
If @error Then
MsgBox(48, "Error", "Error sending specified request.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 4
EndIf
; 等待应答
_WinHttpReceiveResponse($hRequest)
; 检查是否有可用于读取的数据
Global $sChunk
If _WinHttpQueryDataAvailable($hRequest) Then
While 1
If @error Then ExitLoop
MemoWrite($sChunk)
Wend
Else
MsgBox(48, "Error occurred", "Site is experiencing problems.")
EndIf
; 关闭句柄
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; 向memo控件写入信息
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite 这个得问汉化作者及参与者: thesnow 、131738 、netegg 等{:face (355):} 以个烧制 一个炒饭 还有一个是? 回复 2# afan
在我心中,你们都是老大. If _WinHttpQueryDataAvailable($hRequest) Then
while 1
;这行下面加一行
$sChuck = _winhttpreaddata($hRequest)
修改例子的时候没注意 回复 5# netegg
发送请求时出错:Error sending specified request, _WinHttpSendRequest($hRequest)怎么无法实现?
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#Include <WinHttp.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $sTarget
Global $iMemo
Global $sChunk
_Main()
Func _Main()
; 创建界面
GUICreate("HTTP Status", 800, 600)
; 创建memo控件
$iMemo = GUICtrlCreateEdit("", 2, 2, 796, 596, $WS_VSCROLL)
GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
GUISetState()
; 初始化并获取会话句柄
Global $hOpen = _WinHttpOpen()
If @error Then
MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
Exit 1
EndIf
; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, "www.sohu.com")
If @error Then
MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
_WinHttpCloseHandle($hOpen)
Exit 2
EndIf
; 创建请求
Global $hRequest = _WinHttpOpenRequest($hConnect, Default, $sTarget)
If @error Then
MsgBox(48, "Error", "Error creating an HTTP request handle.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 3
EndIf
; 发送请求
_WinHttpSendRequest($hRequest)
If @error Then
MsgBox(48, "Error", "Error sending specified request.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 4
EndIf
; 等待应答
_WinHttpReceiveResponse($hRequest)
; 检查是否有可用于读取的数据
If _WinHttpQueryDataAvailable($hRequest) Then
While 1
$sChuck = _winhttpreaddata($hRequest)
If @error Then ExitLoop
MemoWrite($sChunk)
Wend
Else
MsgBox(48, "Error occurred", "Site is experiencing problems.")
EndIf
; 关闭句柄
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
; 向memo控件写入信息
Func MemoWrite($sMessage = "")
GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite Global $hConnect = _WinHttpConnect($hOpen, "www.sohu.com")改成
Global $hConnect = _WinHttpConnect($hOpen, "sohu.com")试试 回复 7# netegg
还是一样?
另外,Global $sChunk已定义,怎么还是未声明或未创建? 回复 8# newuser
不知道你怎么写的,这是我的运行结果 这个得问汉化作者及参与者: thesnow 、131738 、netegg 等
afan 发表于 2010-11-16 16:04 http://www.autoitx.com/images/common/back.gif
提到在下则回复一声,我怎么查不到这个函数啊。。。。 _winhttpreaddata() 本帖最后由 131738 于 2010-11-16 18:07 编辑
提到在下则回复一声,我怎么查不到这个函数啊。。。。 _winhttpreaddata()
131738 发表于 2010-11-16 17:56 http://www.autoitx.com/images/common/back.gif
找到了, 3361-2新添函数 呵呵。。。。还没看过,
网络通讯类的吧。。。。。而且示例脚本中有这个函数的应用语句! 回复 9# netegg
是用6楼的代码吗?能打包提供吗!包括那些include的文件,谢谢。 1楼代码:
59-62行换成:
MemoWrite(BinaryToString(_WinHttpReadData($hRequest,2, _WinHttpQueryHeaders($hRequest,$WINHTTP_QUERY_CONTENT_LENGTH))))
即可。 While 1
$sChuck = _winhttpreaddata($hRequest)
If @error Then ExitLoop
MemoWrite($sChunk)
Wend改成 While 1
MemoWrite(_winhttpreaddata($hRequest))
If @error Then ExitLoop
Wend 回复 14# netegg
应该是这段出了问题,提示:Error sending specified request,但是$hRequest = _WinHttpOpenRequest($hConnect, Default, $sTarget)应该已经执行过去了,没exit脚本就是代表_WinHttpOpenRequest()返回的句柄成功吧?; 发送请求
_WinHttpSendRequest($hRequest)
If @error Then
MsgBox(48, "Error", "Error sending specified request.")
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
Exit 4
EndIf
页:
[1]
2