本帖最后由 drunk 于 2011-5-3 18:20 编辑
郁闷,返回的cookies和我直接用ie登陆httpwatch查看返回的cookies不同,不知道登陆成功了没啊
哪位朋友有时间帮忙看看,刚接触这个,头疼啊
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include "WinHttp.au3"
Opt("MustDeclareVars", 1)
; !!!注意,如果用户名和密码无效,这个例子将失败!!!
; 认证数据
Global $sUsername = "******@126.com"
Global $sPassword = "******"
; 地址
Global $sAddress = "renren.com"
; 初始化并获得会话句柄
Global $hOpen = _WinHttpOpen("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)")
; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)
; 请求
Global $hRequest = _WinHttpOpenRequest($hConnect, _
"POST", _ ; 动词
"PLogin.do", _ ; 目标
Default, _ ; 版本
"http://www.renren.com/") ; 提交
; 发送
_WinHttpSendRequest($hRequest, _
"Content-Type: application/x-www-form-urlencoded" & @CRLF, _
"email="&$sUsername&"&password="&$sPassword&"&origURL=http%3A%2F%2Fwww.renren.com%2Fhome&domain=renren.com")
; 等待响应
_WinHttpReceiveResponse($hRequest)
; 看看有返回什么
If _WinHttpQueryDataAvailable($hRequest) Then
Global $sHeader = _WinHttpQueryHeaders($hRequest)
MsgBox(0,0,$sHeader)
; 检查是否给予适当的 cookie
If StringInStr($sHeader, 'Set-Cookie: uchomeloginuser=' & $sUsername) Then
MsgBox(0, "", "登录成功")
Else
MsgBox(0, "", "登录失败")
EndIf
Else
MsgBox(48, "错误", "网站遇到的问题.")
EndIf
; 关闭打开的句柄并退出
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
|