今天看到火狐的有个user-Agent插件,可以模拟手机浏览。忽然想到是否可以用post模拟手机登陆过程。于是抓了如下的包:
POST /passport/ HTTP/1.1
Host: wappass.baidu.com
User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://wappass.baidu.com/passport
Cookie: BAIDUID=342CF706118C86AABBD91A618459A887:FG=1; BAIDU_WISE_UID=wiaui_1314978713_2889; WAPTIME=1314980573; BAIDU_WK_MODE=2; BAIDU_WAP_WENKU=56a2984cfe4733687e21aac4_1_1_4500_3_1_3_iphone; BDUSS=pHbC1OYW0yRE9HdnNESXVLaGxVcHA2fjFmYUo3Y2RjZHh3cUhneG5JfmRqNGhPQUFBQUFBJCQAAAAAAAAAAAoawyvvszYU0~DB1szsz8IwNgAAAAAAAAAAAAAAAAAAAAAAAAAAAADgKiV1AAAAAOAqJXUAAAAAcF1CAAAAAAAxMC4yMy4yNN0CYU7dAmFORm
Content-Type: application/x-www-form-urlencoded
Content-Length: 184
login_username=autoitxxx&login_loginpass=autoit36&login_save=0&aaa=%E7%99%BB%E5%BD%95&login=yes&can_input=0&u=&tpl=&tn=&pu=&ssid=&from=&bd_page_type=&uid=
写下如下的代码
$oHTTP = ObjCreate("microsoft.xmlhttp");还是需要WinHttp.WinHttpRequest.5.1呢
$strPost="login_username="&AnsiURLEncode("autoitxxx")&"&login_loginpass="&AnsiURLEncode("autoit36")&"&login_save=0&aaa=%E7%99%BB%E5%BD%95&login=yes&can_input=0&u=&tpl=&tn=&pu=&ssid=&from=&bd_page_type=&uid="
$oHTTP.Open("post","http://wappass.baidu.com/passport/",false)
$oHTTP.setRequestHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0")
$oHTTP.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
$oHTTP.setRequestHeader("Accept-Encoding", "gzip,deflate")
$oHTTP.setRequestHeader("Accept-Language", "en-us,en;q=0.5")
$oHTTP.setRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
$oHTTP.Send($strPost);post关键数据
ConsoleWrite($oHTTP.responsetext)
Func AnsiURLEncode($str, $falg = 0);by afan
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
问题出在用ObjCreate("microsoft.xmlhttp")无法正常登陆,而用ObjCreate("WinHttp.WinHttpRequest.5.1")执行到$oHTTP.Send($strPost);post关键数据出错。不知道问题在哪里,望各位指教,多谢多谢! |