找回密码
 加入
搜索
查看: 6248|回复: 2

[网络通信] 用user-Agent仿手机客户端post登陆百度的问题

[复制链接]
发表于 2011-9-3 00:59:49 | 显示全部楼层 |阅读模式
今天看到火狐的有个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关键数据出错。不知道问题在哪里,望各位指教,多谢多谢!
发表于 2011-9-3 07:58:52 | 显示全部楼层
本帖最后由 republican 于 2011-9-3 08:01 编辑

回复 1# papapa314

呵呵,最关键的代码居然不写。
$oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1");还是需要WinHttp.WinHttpRequest.5.1呢

                

                $strPost="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.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("Content-Type", "application/x-www-form-urlencoded")
                $oHTTP.setRequestHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")

                

                $oHTTP.Send($strPost);post关键数据

 

                ConsoleWrite($oHTTP.responsetext)

想post,Content-Type是必须得。

winhttp的所有方法必须大写。

附带我自己写的

#include 'Winhttp_GetRespond.au3'
$MyOpen=_WinHttpOpen('Opera/9.80 (Windows NT 5.2; U; zh-cn) Presto/2.6.30 Version/10.63')

_WinHTTP_GetRespond($MyOpen,'http://wappass.baidu.com/passport/')                ;取Cookies
$strPost="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="
$rContext=_WinHTTP_GetRespond($MyOpen,'http://wappass.baidu.com/passport/',1+2+4,-1,$strPost,-1,'Content-Type: application/x-www-form-urlencoded'&@CRLF&'Referer: http://wappass.baidu.com/passport/')         
ConsoleWrite($rContext[6]&@CRLF)
ConsoleWrite($rContext[0])
 
 _WinhttpClosehandle($MyOpen)


擦,本论坛链接自动加URL

评分

参与人数 1金钱 +20 收起 理由
papapa314 + 20

查看全部评分

 楼主| 发表于 2011-9-3 16:13:30 | 显示全部楼层
回复 2# republican


    多谢,又让你帮忙啦。之前都是用ObjCreate("microsoft.xmlhttp"),不需要写content type的也可以成功,但microsoft.xmlhttp似乎不能用在wap上,换了ObjCreate("WinHttp.WinHttpRequest.5.1")就没写content type,怪不得出错了。看来还是对post的相关知识不大了解,需要进一步学习。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-25 00:42 , Processed in 0.077325 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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