本帖最后由 chenronting 于 2012-7-7 21:08 编辑
大家好,下面是我看了论坛里的东西后,自己弄出的一个登陆代码 ,可是得到的信息好像是登陆失败了。
请问我这个代码里有哪里是不对的吗,另,如何显示一个IE窗口,来测试是否成功 。
在此谢过!!!
原来是Get地址不对。。不过我也不知道为什么不对。!
#include <Array.au3>
#include <WinHttp_GetRespond.au3>
;Opt("MustDeclareVars",1)
Global $MyOpen,$rContext
$MyOpen=_WinHttpOpen()
$rContext=_WinHTTP_GetRespond($MyOpen,"http://zhidao.baidu.com/html/userlogin.html?t=1337390692718",2+4)
_ArrayDisplay($rContext,'Debug~~~')
;$ck = StringRegExp($rContext[3],'(BAIDUID=.+;) expires',3)
;$ck = $ck[0]
$ck = $rContext[3]
$Name = AnsiURLEncode('你自己的用户名')
$PassWord = AnsiURLEncode('你自己的密码')
$rContext=_WinHTTP_GetRespond($MyOpen,"https://passport.baidu.com/v2/api/?login",1 + 2 + 4,50000, _
"charset=gb2312&codestring=&token=6f4ff0a44bfbc5e06e5165b9808c9b71&isPhone=false&index=0&u=http%3A%2F%2Fzhidao.baidu.com/&safeflg=0&staticpage=http%3A%2F%2Fzhidao.baidu.com%2Fhtml%2Fjump.html&" & _
"loginType=1&tpl=ik&callback=parent.bdPass.api.login._postCallback&username=" & $Name & "&password=" & $PassWord & "&verifycode=", _
$ck,"Content-Type: application/x-www-form-urlencoded")
If @error Then MsgBox(0,"Error","登录失败")
MsgBox(0,1,$rContext[0])
_ArrayDisplay($rContext)
$rContext=_WinHTTP_GetRespond($MyOpen,"http://zhidao.baidu.com/submit/user",1,0,"cm=100509&t=1337391020625",$ck)
If @error Then MsgBox(0,"Error","失败")
_ArrayDisplay($rContext)
$rContext=_WinHTTP_GetRespond($MyOpen,"http://zhidao.baidu.com",2,0,"",$ck)
If @error Then MsgBox(0,"Error","获取失败")
MsgBox(64,2,StringTrimLeft($rContext[0],1000))
_WinHttpCloseHandle($MyOpen)
Func AnsiURLEncode($str, $falg = 0)
Local $str_s = StringRegExpReplace($str, '^(http://).+', '$1')
If @extended = 0 Then $str_s = ''
If @extended > 0 Then $str = StringRegExpReplace($str, '^http://', '')
Local $astr, $i, $s2d, $sS = StringSplit($str, '')
For $i = 1 To UBound($sS) - 1
If StringRegExp($sS[$i], '[^\x00-\xff]') Then
$s2d = StringToBinary($sS[$i] & ' ')
$astr &= '%' & StringMid($s2d, 3, 2) & '%' & StringMid($s2d, 5, 2)
ElseIf StringRegExp($sS[$i], '[^\w]') Then
$s2d = StringToBinary($sS[$i])
$astr &= '%' & StringMid($s2d, 3, 2)
Else
If $falg = 0 Then $astr &= $sS[$i]
If $falg <> 0 Then
$s2d = StringToBinary($sS[$i])
$astr &= '%' & StringMid($s2d, 3, 2)
EndIf
EndIf
Next
$astr = StringReplace($astr, '%20', '+') ;转换空格的编码为'+'号,也可不要此行
Return $str_s & $astr
EndFunc ;==>AnsiURLEncode
|