本帖最后由 fpquenya 于 2012-7-2 15:48 编辑
以本论坛为例,通过POST可以返回"欢迎回来xx会员信息",但没有在IE窗口中进行登录,如何让IE也自动是已登录的状态呢?已搜索过,可能跟Cookie有关,但还是没有什么头绪,求大大们指点一二.感谢!
下面附代码.
;GET方法得到响应的文本内容
Local $oHTTP
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
$oHTTP.Option(4) = 13056 ;忽略错误标志
$oHTTP.Option(6) = True ;是否接收重定向地址信息
$oHTTP.SetTimeouts(30000, 30000, 30000, 30000);超时时间设置
$oHTTP.Open("GET","http://www.autoitx.com/logging.php?action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login",False)
$oHTTP.Send()
Local $sResponse = BinaryToString($oHTTP.ResponseBody)
;正则得到formhash值
Local $exp1 = '',$exp2 = '',$exp3 = ''
$exp1 = StringRegExp($sResponse,'(?i)formhash=(\w+)',3)
Local $formhash
If Not @error Then $formhash = $exp1[0]
;正则得到cookietime值
Local $cookietime = ''
$exp2 = StringRegExp($sResponse,'(?i)cookietime.+?value="(\d+)"',3)
If Not @error Then $cookietime = $exp2[0]
;提交post数据
Local $referer = "http%3A%2F%2Fwww.autoitx.com%2Findex.php" ;首页
Local $user = "fpquenya" ;帮忙测试需要修改
Local $password_MD5 = "************" ;帮忙测试需要修改
Local $postdata = 'formhash=' & $formhash & '&referer=' & $referer & '&loginfield=username&username=' & _
$user & '&password=' & $password_MD5 & '&questionid=0&answer=&cookietime=' & $cookietime
$oHTTP.Open("POST",'http://www.autoitx.com/logging.php?action=login&loginsubmit=yes&floatlogin=yes&inajax=1',False)
$oHTTP.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
$oHTTP.Send($postdata)
;提交后返回内容
Local $postResponse = BinaryToString($oHTTP.ResponseBody)
$exp3 = StringRegExp($postResponse,"<p>(.*?)</p>",3)
If Not @error Then MsgBox(64,"登录成功",$exp3[0])
|