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

[网络通信] [已解决]请教WinHTTP UDF具体用法

[复制链接]
发表于 2011-5-3 14:52:38 | 显示全部楼层 |阅读模式
本帖最后由 drunk 于 2011-5-3 17:56 编辑

哪位帮忙看一下啊,我这个是直接用的示例,账号已经注册了,为什么登陆不成功呢
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; !!!注意,如果用户名和密码无效,这个例子将失败!!!

; 认证数据
Global $sUsername = "idrunk"
Global $sPassword = "1397361dt"

; 地址
Global $sAddress = "space.livevn.com"

; 初始化并获得会话句柄
Global $hOpen = _WinHttpOpen()

; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)

; 请求
Global $hRequest = _WinHttpOpenRequest($hConnect, _
        "POST", _ ; 动词
        "/do.php?ac=091e9036ad660fc544fcb2eb3ce7be65&&ref", _    ; 目标
        Default, _ ; 版本
        "http://space.livevn.com/index.php", _    ; 提交
        "*/*") ; 接受

; 发送
_WinHttpSendRequest($hRequest, _
        "Content-Type: application/x-www-form-urlencoded" & @CRLF, _
        "username="&$sUsername&"&password="&$sPassword&"&cookietime=315360000&refer=%2F&abc=&loginsubmit=%C4%90%C4%83ng+nh%E1%BA%ADp+&formhash=984798db")

; 等待响应
_WinHttpReceiveResponse($hRequest)

; 看看有返回什么
If _WinHttpQueryDataAvailable($hRequest) Then
    Global $sHeader = _WinHttpQueryHeaders($hRequest)
    ConsoleWrite($sHeader & @CRLF)
    ; 检查是否给予适当的 cookie
    If StringInStr($sHeader, 'Set-Cookie: uchome_loginuser=' & $sUsername) Then
        MsgBox(0, "", "登录成功")
    Else
        MsgBox(0, "", "登录失败")
    EndIf
Else
    MsgBox(48, "错误", "网站遇到的问题.")
EndIf


; 关闭打开的句柄并退出
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
 楼主| 发表于 2011-5-3 15:51:25 | 显示全部楼层
不要沉了
 楼主| 发表于 2011-5-3 16:05:45 | 显示全部楼层
哈哈,登陆成功了,那个网站可能有点小变化,稍微改下就可以了
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; !!!注意,如果用户名和密码无效,这个例子将失败!!!

; 认证数据
Global $sUsername = "idrunk"
Global $sPassword = "1397361dt"

; 地址
Global $sAddress = "www.livevn.com"

; 初始化并获得会话句柄
Global $hOpen = _WinHttpOpen()

; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)

; 请求
Global $hRequest = _WinHttpOpenRequest($hConnect, _
        "POST", _ ; 动词
        "/do.php?ac=091e9036ad660fc544fcb2eb3ce7be65&&ref", _    ; 目标
        Default, _ ; 版本
        "http://www.livevn.com/", _    ; 提交
        "*/*") ; 接受

; 发送
_WinHttpSendRequest($hRequest, _
        "Content-Type: application/x-www-form-urlencoded" & @CRLF, _
        "username="&$sUsername&"&password="&$sPassword&"&cookietime=315360000&refer=%2F&abc=&loginsubmit=%C4%90%C4%83ng+nh%E1%BA%ADp+&formhash=984798db")

; 等待响应
_WinHttpReceiveResponse($hRequest)

; 看看有返回什么
If _WinHttpQueryDataAvailable($hRequest) Then
    Global $sHeader = _WinHttpQueryHeaders($hRequest)
    ConsoleWrite($sHeader & @CRLF)
    ; 检查是否给予适当的 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)
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 23:32 , Processed in 0.079332 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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