创建一个HTTP请求句柄
#Include <WinHttp.au3>
_WinHttpOpenRequest($hConnect [, $sVerb = Default [, $sObjectName = Default [, $sVersion = Default [, $sReferrer = Default [, $sAcceptTypes = Default [, $iFlags = Default ]]]]]])
$hConnect | 由 _WinHttpConnect() 函数返回的 HTTP 会话句柄. |
$sVerb | [可选参数] 请求使用的 HTTP 操作. 默认为"GET". |
$sObjectName | [可选参数] 指定HTTP操作的目标资源名称. |
$sVersion | [可选参数] HTTP 版本. 默认为 "HTTP/1.1" |
$sReferrer | [可选参数] 请求 $sObjectName 文档时的URL引用. 默认为 $WINHTTP_NO_REFERER. |
$sAcceptTypes | [可选参数] 指定客户端可接受的媒体类型. 默认为 $WINHTTP_DEFAULT_ACCEPT_TYPES. |
$iFlags | [可选参数] 指定网络标志值的整数. 默认为 $WINHTTP_FLAG_ESCAPE_DISABLE. |
成功: | 返回一个有效会话句柄. |
失败: | 返回 0 并设置 @error: |
1 - DllCall 失败 |
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include "WinHttp.au3"
Opt("MustDeclareVars", 1)
; !!!注意如果用户名和密码无效, 那么此例子将失败!!!
; 身份验证数据
Global $sUsername = "UserName"
Global $sPassword = "Password"
; 地址
Global $sAddress = "space.livevn.com"
; 初始化并获取会话句柄
Global $hOpen = _WinHttpOpen()
; 获取连接句柄
Global $hConnect = _WinHttpConnect($hOpen, $sAddress)
; 请求
Global $hRequest = _WinHttpOpenRequest($hConnect, _
"POST", _ ; 动作
"/do.php?ac=71ee30ae117cddace55bd01714904227&&ref", _ ; 目标
Default, _ ; 版本
"http://space.livevn.com/index.php", _ ; referer
"*/*") ; 接受
; 发送它
_WinHttpSendRequest($hRequest, _
"Content-Type: application/x-www-form-urlencoded" & @CRLF, _
"username=" & $sUsername & "&password=" & $sPassword & "&loginsubmit=&loginsubmit=loginnnnnnnnnnn&refer=network.html&formhash=c51a94db")
; 等待响应
_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, "", "Login success")
Else
MsgBox(0, "", "Login failed")
EndIf
Else
MsgBox(48, "Error", "Site is experiencing problems.")
EndIf
; 关闭打开的句柄并退出
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)