找回密码
 加入
搜索
查看: 12783|回复: 20

[IE类操作] (已解决)这样post为什么不成功,验证码过期了吗?请教!

 火.. [复制链接]
发表于 2011-1-15 02:56:40 | 显示全部楼层 |阅读模式
本帖最后由 papapa314 于 2011-1-20 20:35 编辑

最近在学post,可惜我们论坛没有视频教程,看了一个易语言的post教程,想换用autoit试试,随便找了一个最简单的网站练练手(纯粹是练手),可是为什么post不成功呢?
post的信息是:
POST /MemberReg.asp?Action=Reg HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://xmczjy.com/MemberReg.asp
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: xmczjy.com
Content-Length: 113
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASPSESSIONIDAQRQRCTR=CLPHMPAADBEHJIMFDBOLKLNF

Item1=fkkkkljlkjfj&Item2=123456&fItem2=123456&Item3=&Item4=&Item5=fjljklj@126.com&Code=9963&Submit=+%D7%A2%B2%E1+

代码如下,请教高手问题出在哪?

#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("传智教育网站批量注册", 623, 442, 192, 124)
$Obj1 = ObjCreate("Shell.Explorer.2")
$Obj1_ctrl = GUICtrlCreateObj($Obj1, 224, 16, 154, 76)
$Input1 = GUICtrlCreateInput("1223", 232, 112, 121, 21)
$Label1 = GUICtrlCreateLabel("用户名", 152, 112, 40, 17)
$Label2 = GUICtrlCreateLabel("密码", 152, 160, 28, 17)
$Button1 = GUICtrlCreateButton("刷新验证码和资料", 392, 32, 97, 49)
$Input2 = GUICtrlCreateInput("1223", 232, 160, 121, 21)
$Label3 = GUICtrlCreateLabel("邮箱", 152, 224, 28, 17)
$Input3 = GUICtrlCreateInput("jj@126.com", 232, 224, 121, 21)
$Button2 = GUICtrlCreateButton("注册", 400, 208, 91, 41)
$Input4 = GUICtrlCreateInput("", 512, 40, 97, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$oIE=_IENavigate($Obj1,"about:blank")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $oIE=_IENavigate($Obj1,"http://xmczjy.com/Include/Code.asp?zzqqq"&@SEC )
                        GUICtrlSetData($input1,Random(10000,99999,1)&Random(10000,99999,1))
                        GUICtrlSetData($input2,"1223"&Random(1000,9999,1))
                        GUICtrlSetData($input3,Random(1000,9999,1)&"jj@126.com")
                Case $Button2
                $a=GUICtrlRead($Input1)
                $b=GUICtrlRead($Input2)
                $c=GUICtrlRead($input3)       
                $d=GUICtrlRead($input4)       
                $oHTTP = ObjCreate("microsoft.xmlhttp")

                $oHTTP.Open("post","http://xmczjy.com/MemberReg.asp?Action=Reg",false)

                $oHTTP.setRequestHeader("Cache-Control", "no-cache")

                $oHTTP.setRequestHeader("Accept-Language", "zh-cn")

                $oHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded")  

                $oHTTP.setRequestHeader("Referer","http://xmczjy.com/MemberReg.asp")

                $oHTTP.Send("Item1="&$a&"&Item2="&$b&"&fItem2="&$b&"&Item3=&Item4=&Item5="&$c&"&Code="&$d&"&Submit=+%D7%A2%B2%E1+");

                MsgBox(0,'',BinaryToString($oHTTP.responseText))
                       
                       
        EndSwitch
WEnd
发表于 2011-1-15 05:38:22 | 显示全部楼层
明显是SESSION对不上,验证码你应该用get来获取,虽然_IENavigate也是用get的方式来获取,但是你却读取不到Cookie的数据,或者说你没有读取.
正确的操作是使用$oHTTP.Open里的get来获取验证码,然后获得本次会话的SESSIONID,最后post时再在Header中发送Cookie数据
发表于 2011-1-15 07:59:21 | 显示全部楼层
很好,选了这么简洁的例子.

obj提供的http过程每次都会打开并关闭会话ID,所以很多严格要求的网站会直接拒绝,但此网站应该不会。

这里提供一下我的例子,需要用到我的自定义UDF, winhttp_getrespond,64楼。

代码:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <WinHttp_GetRespondNew.au3>
#include <array.au3>
$MyOpen=_WinHttpOpen()

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("传智教育网站批量注册", 623, 442, 192, 124)


$Pic1 = GUICtrlCreatePic("", 224, 16, 40, 10)
$Input1 = GUICtrlCreateInput("1223", 232, 112, 121, 21)
$Label1 = GUICtrlCreateLabel("用户名", 152, 112, 40, 17)
$Label2 = GUICtrlCreateLabel("密码", 152, 160, 28, 17)
$Button1 = GUICtrlCreateButton("刷新", 392, 32, 97, 49)
$Input2 = GUICtrlCreateInput("1223", 232, 160, 121, 21)
$Label3 = GUICtrlCreateLabel("邮箱", 152, 224, 28, 17)
$Input3 = GUICtrlCreateInput("jj@126.com", 232, 224, 121, 21)
$Button2 = GUICtrlCreateButton("注册", 400, 208, 91, 41)
$Input4 = GUICtrlCreateInput("", 512, 40, 97, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $ASPSESSIONIDCSCDARTQ

$rContext=_WinHTTP_GetRespond($MyOpen,"http://xmczjy.com/MemberReg.asp",4 + 2,50000,"","webim_login_status=0")
If @error Then MsgBox(0,@error,"出错了")
;~ MsgBox(0,$rContext[3],$rContext[6])
;~ MsgBox(0,"内容",BinaryToString($rContext[0]))
$ASPSESSIONIDCSCDARTQ = StringRegExpReplace($rContext[3],"(ASPSESSIONIDCSCDARTQ=.*?);.*","$1")
_Get_Code()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                                Case $GUI_EVENT_CLOSE
                                                _WinHttpCloseHandle($MyOpen) 
                        Exit
                Case $Button1
                                                _Get_Code()
                        
                                Case $Button2
                                
                                $Context = "Item1="&GUICtrlRead($Input1)&"&Item2="&GUICtrlRead($Input2)&"&fItem2="&GUICtrlRead($Input2)&"&Item3=&Item4=&Item5="&GUICtrlRead($input3) &"&Code="&GUICtrlRead($input4)&"&Submit=+%D7%A2%B2%E1+"
                                $rContext=_WinHTTP_GetRespond($MyOpen,"http://xmczjy.com/MemberReg.asp?Action=Reg",1 + 4 + 2 + 8,50000,$Context,$ASPSESSIONIDCSCDARTQ,"Content-Type: application/x-www-form-urlencoded")
                                If @error Then MsgBox(0,@error,"出错了")
                                MsgBox(0,$rContext[3],$rContext[6])
                                MsgBox(0,"跳转即成功",BinaryToString($rContext[0]))
                                Sleep(200)
                                
                                $rContext=_WinHTTP_GetRespond($MyOpen,'http://xmczjy.com/Member.asp?Action=Logout',0 ,50000,"",$ASPSESSIONIDCSCDARTQ)        ;注销,方便再次注册
                        
        EndSwitch
WEnd
        
Func _Get_Code()
        GUICtrlSetData($input1,Random(10000,99999,1)&Random(10000,99999,1))
        GUICtrlSetData($input2,"1223"&Random(1000,9999,1))
        GUICtrlSetData($input3,Random(1000,9999,1)&"jj@126.com")
        
        $rContext=_WinHTTP_GetRespond($MyOpen,"http://xmczjy.com/Include/Code.asp?"&@SEC ,4 + 2 ,50000,"",$ASPSESSIONIDCSCDARTQ)

        If @error Then Return MsgBox(0,@error,"出错了")

        $CodeFile = FileOpen(@ScriptDir & "\code.bmp",10)
        FileWrite($CodeFile,Binary($rContext[0]))
        FileClose($CodeFile)
        GUICtrlSetImage($Pic1,@ScriptDir & "\code.bmp")

EndFunc        


代码及编译程序打包下载。

本帖子中包含更多资源

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

×
 楼主| 发表于 2011-1-15 14:17:34 | 显示全部楼层
回复 3# republican


谢谢republican ,不过要搞懂你的程序可能还得费一番思量,不过我会努力的
 楼主| 发表于 2011-1-15 14:19:22 | 显示全部楼层
回复 2# ceoguang

谢谢你的帮助!请问用你的方法的话,具体应该怎么操作,能不能给一个例子呢?
发表于 2011-1-15 15:38:04 | 显示全部楼层
回复  ceoguang

谢谢你的帮助!请问用你的方法的话,具体应该怎么操作,能不能给一个例子呢?
papapa314 发表于 2011-1-15 14:19

3#不是吗?
原理是一样的
 楼主| 发表于 2011-1-15 16:21:27 | 显示全部楼层
回复 6# ceoguang

呵呵,我还以为有不同的方法呢,如果能够同时学会两种方法岂不是更好,谢谢哦
 楼主| 发表于 2011-1-15 16:38:59 | 显示全部楼层
回复 3# republican


$rContext=_WinHTTP_GetRespond($MyOpen,"http://xmczjy.com/MemberReg.asp",4 + 2,50000,"","webim_login_status=0")

这个地方看不懂,按照你的UDF,“webim_login_status=0”填写的应该是cookie,问题是字符串“webim_login_status”是从哪里得到的呢?或者说这个字符串是什么意思呢?
发表于 2011-1-15 17:09:55 | 显示全部楼层
回复 8# papapa314

哦,这个是忘了删掉的..呵呵..

昨天写飞信登录脚本需要而已,今天改的时候忘了去掉。不影响结果的。
 楼主| 发表于 2011-1-15 21:04:41 | 显示全部楼层
回复 9# republican

呵呵,谢谢,是个好老师,例子很有启发性。现在搞懂了,已经自己从头写过一遍了。不过还有这问题,为什么要对得到的那个cookie字符串进行替换?
我把那替换语句删掉,然后不填写cookie结果好像也没变。不过还是想知道是做什么用的?
发表于 2011-1-15 21:34:03 | 显示全部楼层
只是让结果更精确。

此网站可能没问题,但不知道其他网站如何,所以就稳妥一点。
 楼主| 发表于 2011-1-15 21:39:38 | 显示全部楼层
恩,那为什么不把整个cookie都写进去,而要取其中一部分呢
发表于 2011-1-15 22:03:37 | 显示全部楼层
你截得包应该没有path;字样吧.
再说,cookies也不是全部都需要。
 楼主| 发表于 2011-1-15 22:55:03 | 显示全部楼层
把cookies全部写进去也没问题吧?不懂为什么要那样替换,所以还是想偷懒全部写进去。
发表于 2011-1-21 10:43:00 | 显示全部楼层
这里提供一下我的例子,需要用到我的自定义UDF, winhttp_getrespond,64楼。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 00:53 , Processed in 0.081675 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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