winhttp post问题,总报验证码错误
本帖最后由 aaron20020524 于 2013-10-31 00:35 编辑post的时候总报验证码错误,不知道哪里出问题了,请大侠们帮帮忙,我是小白,谢谢
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinHttp_GetRespond.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$NEW_STYLE=BitOR($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_SYSMENU,$WS_EX_TRANSPARENT) ;透明效果
$Form1 = GUICreate("Form1", 337, 201,-1, -1) ;透明效果
$Input1 = GUICtrlCreateInput("", 24, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 24, 64, 121, 21)
$Input3 = GUICtrlCreateInput("", 24, 96, 121, 21)
$Pic1 = GUICtrlCreatePic("", 168, 80, 86, 28)
$Button1 = GUICtrlCreateButton("重新获取", 184, 128, 75, 25)
$Button2 = GUICtrlCreateButton("登录", 24, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
#cs
注册ANIGIF控件
#ce
FileCopy(@ScriptDir & '\AniGIF.ocx',@SystemDir & "\", 1)
RunWait('REGSVR32 /S ' & @SystemDir & "\AniGIF.ocx")
;解除注册
;~ RunWait('REGSVR32 /U /S ' & @SystemDir & "\AniGIF.ocx")
_WinAPI_SetLayeredWindowAttributes ($Form1,0x010101,190) ;透明效果
$Obj_gif = ObjCreate("AniGIFCtrl.AniGIF") ;创建AniGIF对象
$id_ctrl_gif = GUICtrlCreateObj($Obj_gif, 176, 8, 700,460)
Global $seccode_update,$idhash,$loginhash,$formhash,$header_cookie
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;$idhash
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP = ObjCreate("MSXML2.XMLHTTP")
$oHTTP.Open("GET","http://www.macx.cn/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login",false)
$oHTTP.setRequestHeader("Accept-Language", "zh-cn")
$oHTTP.setRequestHeader("Connection", "Keep-Alive")
$oHTTP.setRequestHeader("Referer", "http://www.macx.cn/")
$oHTTP.Send()
$data=$oHTTP.responseText
$header=$oHTTP.GetAllResponseHeaders
$header_cookie = StringRegExp($header, "MacX_4.*?;", 3)
_ArrayDisplay($header_cookie)
$idhash="SA"&StringMid ($header_cookie,15,6)&"0"
$loginhash_start=StringInStr ($data,"main_messaqge",0,1,1)
$loginhash=StringMid ($data,$loginhash_start+14,5)
$formhash_start=StringInStr ($data,"formhash",0,1,1)
$formhash=StringMid ($data,$formhash_start+17,8)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;$seccode_update
$oHTTP.Open("GET","http://www.macx.cn/misc.php?mod=seccode&action=update&idhash="&$idhash&"&inajax=1&ajaxtarget=seccode_"&$idhash,false)
$oHTTP.setRequestHeader("Accept-Language", "zh-cn")
$oHTTP.setRequestHeader("Connection", "Keep-Alive")
$oHTTP.setRequestHeader("Referer", "http://www.macx.cn/")
$oHTTP.Send()
$data=$oHTTP.responseText
$seccode_update_start=StringInStr ($data,"seccode&update",0,1,1)
$seccode_update=StringMid ($data,$seccode_update_start+15,5)
_Get_Code()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
_Get_Code()
Case $Button2
_Login()
EndSwitch
WEnd
Func _Get_Code()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;get验证图
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("GET","http://www.macx.cn/misc.php?mod=seccode&update="&$seccode_update&"&idhash="&$idhash,false)
$oHTTP.setRequestHeader("Accept-Language", "zh-cn")
$oHTTP.setRequestHeader("Connection", "Keep-Alive")
$oHTTP.setRequestHeader("Referer", "http://www.macx.cn/")
$oHTTP.setRequestHeader("Cookie", "PHPSESSID=fk36bki5k1iukulup0gi0ca1mrfkmsui")
$oHTTP.Send()
$alldata=$oHTTP.ResponseBody
If @error Then Return MsgBox(0,@error,"出错了")
$CodeFile = FileOpen(@ScriptDir & "\code.gif",10)
FileWrite($CodeFile,Binary($alldata))
FileClose($CodeFile)
GUICtrlSetImage($Pic1,@ScriptDir & "\code.gif")
$Obj_gif.ReadGIF(@ScriptDir & "\code.gif") ;gif动画path。全路径,相对路径均可
;~ $Obj_gif.Transparent=True ;透明设置,好像没JBD用
$Obj_gif.Speed=1 ;播放速度。1-正常;数字增大速度变慢;
$Obj_gif.Play ;播放
RunWait('REGSVR32 /U /S ' & @SystemDir & "\AniGIF.ocx")
EndFunc
Func _Login()
$post_url="http://www.macx.cn/member.php?mod=logging&action=login&loginsubmit=yes&handlekey=login&loginhash="&$loginhash&"&inajax=1"
$post_data="formhash="&$formhash&"&referer=http%3A%2F%2Fwww.macx.cn%2F&username="&GUICtrlRead($Input1)&"&password="&GUICtrlRead($Input2)&"&questionid=0&answer=&sechash="&$idhash&"&seccodeverify="&GUICtrlRead($Input3)
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Open("POST",$post_url,false)
$oHTTP.setRequestHeader("Accept-Language", "zh-cn")
$oHTTP.setRequestHeader("Cache-Control", "no-cache")
$oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
$oHTTP.setRequestHeader("Referer","http://www.macx.cn/")
$oHTTP.setRequestHeader("Cookie", "PHPSESSID=fk36bki5k1iukulup0gi0ca1mrfkmsui")
$oHTTP.setRequestHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)")
$oHTTP.Send($post_data);post关键数据
$data=$oHTTP.responseText
$header=$oHTTP.GetAllResponseHeaders
MsgBox(0,0,$data)
EndFunc $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP = ObjCreate("MSXML2.XMLHTTP")
这两句有问题啊。
怎么变量一样了。 这2个你可以定义不一样的变量啊。比如
$oHTTP1 = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP2 = ObjCreate("MSXML2.XMLHTTP") 回复 2# netsmu
谢谢你的回复,不好意思,我发帖时代码贴多了,$oHTTP = ObjCreate("MSXML2.XMLHTTP")实际我是已经删除,整个代码都只是用$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1"),但调试出来还是报验证码填写错误 $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")用全局变量,子函数中不要再创建了
页:
[1]