#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
$Form1 = GUICreate("Form1", 617, 438, 192, 114)
$Obj1 = ObjCreate("Shell.Explorer.2")
$Obj1_ctrl = GUICtrlCreateObj($Obj1, 0, 0, 616, 400)
GUISetState(@SW_SHOW)
_IENavigate($Obj1, "www.odnoklassniki.ru")
_IELoadWait($Obj1)
_IEzap($Obj1, 0, 2, 'логин')
_IEzap($Obj1, 0, 3, 'пароль')
_IEclick($Obj1, 0, 9, 'Войти')
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _IEclick($IESET, $form, $index, $name)
$oForm = _IEFormGetCollection($IESET, $form)
Do
$oSubmit = _IEFormElementGetCollection($oForm, $index)
Until StringStripWS(_IEFormElementGetValue($oSubmit), $index) = $name
_IEAction($oSubmit, "click")
EndFunc ;==>_IEclick
Func _IEzap($IESET, $form, $index, $text)
$oForm = _IEFormGetCollection($IESET, $form)
$oText = _IEFormElementGetCollection($oForm, $index)
_IEFormElementSetValue($oText, $text)
EndFunc ;==>_IEzap
Вот что выдаёт мне снифер при ручной авторизации:Через WinHttp.WinHttpRequest.5.1
Request URL:https://www.ok.ru/https
Request Method:POST
Status Code:302 Moved Temporarily
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Type:application/x-www-form-urlencoded
Origin:http://ok.ru
Referer:http://ok.ru/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.22 Safari/537.36 OPR/16.0.1196.14 (Edition Next)
Form Dataview sourceview URL encoded
st.redirect:
st.asr:
st.posted:set
st.originalaction:http://ok.ru/dk?cmd=AnonymLogin&st.cmd=anonymLogin
st.fJS:enabled
st.st.screenSize:1680 x 1050
st.st.browserSize:628
st.st.flashVer:14.0.0
st.email:mylogin
st.password:mypass
st.remember:on
st.iscode:false
Но у меня не получается сделать
class Odnoklassniki_API {
public function __construct($email, $passwd)
{
$this->email = $email;
$this->passwd = $passwd;
$this->user_agent = $_SERVER['HTTP_USER_AGENT'];
if (isset($this->email) && isset($this->passwd))
{
// autenticate the user
if ( ! $this->authenticate())
{
throw new Exception('Failed to authenticate, please check your email and password.');
}
}
}
private function authenticate()
{
$postdata = array(
'st.redirect' => '',
'st.posted' => 'set',
'st.email' => $this->email,
'st.password' => $this->passwd,
'st.screenSize' => '',
'st.browserSize' => '',
'st.flashVer' => ''
);
$response = $this->post_to("http://www.odnoklassniki.ru/dk?cmd=AnonymLogin&st.cmd=anonymLogin&tkn=2039", $postdata);
//process the response;
if ($response)
{
// Проверка ответа authenticate?
var_dump($response);
return true;
}
return false;
}
private function post_to($url, $data=array())
{
//check that the url is provided
if ( ! isset($url))
{
return false;
}
//send the data by curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
if (count($data) > 0)
{
//POST METHOD
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
$response = curl_exec($ch);
curl_close($ch);
return $response
}
всё что мне нужно получить, так это jsessionid
Local $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1")
Local $sPostData = _
"st.redirect=" _
&"&st.posted=set" _
&"&[email protected]" _
&"&st.password=123456789" _
&"&st.screenSize=" _
&"&st.browserSize=" _
&"&st.flashVer="
$oHTTP.Open("POST", 'http://www.odnoklassniki.ru/dk?cmd=AnonymLogin&st.cmd=anonymLogin&tkn=2039', false)
$oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36")
$oHTTP.SetRequestHeader("Host", "www.ok.ru")
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
$oHTTP.SetRequestHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4")
$oHTTP.SetRequestHeader("Connection", "keep-alive")
$oHTTP.Send($sPostData)
ConsoleWrite($oHTTP.Status & @cr)
ConsoleWrite($oHTTP.StatusText & @cr)
;~ ConsoleWrite($oHTTP.GetAllResponseHeaders & @cr)
ConsoleWrite($oHTTP.GetResponseHeader('Set-Cookie') & @cr)
Прошу прощения забыл! Поправил.Здесь не используется $sPostData
PostData возвращается при авторизации на сайте в заголовке. Просто зайдите на сайт через браузер, и отправьте пустой запрос (без логина и пароля). В заголовке вернутся все поля:как её указать?
st.redirect:
st.asr:
st.posted:set
st.originalaction:http://www.odnoklassniki.ru/dk?cmd=AnonymLogin&st.cmd=anonymLogin
st.fJS:enabled
st.st.screenSize:1680 x 1050
st.st.browserSize:395
st.st.flashVer:14.0.0
st.email:
st.password:
st.remember:on
st.iscode:false
Всё равно авторизация не проходит ...Если не использовать $sPostData, это равносильно тому что авторизация не прошла.
; ========== private variables ========== ;
Global $oReq, $oSC, $sUrl, $sUserAgent, $sSendStr, $GetAllResponseHeaders
Global $aTmp
Global $SetCookie = "", $Cookie = ""
; ========== end private variables ========== ;
; ========== public functions ========== ;
Func _ok_login($email = "", $password = "")
$oReq = ObjCreate('WinHttp.WinHttpRequest.5.1')
$oSC = ObjCreate("ScriptControl")
If Not IsObj($oReq) Or Not IsObj($oSC) Then
;//MsgBox(16, 'Error', 'Create object error')
;//Exit 1
Return SetError(1, 0, 0)
EndIf
$oSC.Language = "JavaScript"
$sUserAgent = 'Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0'
For $r = 1 To 2
Switch $r
Case 1
$sUrl = 'https://www.odnoklassniki.ru/https'
$oReq.Open('POST', $sUrl, False)
$oReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
Case 2
$sSendStr = ""
$aTmp = StringRegExp($GetAllResponseHeaders, "(?i)Location:.*?(http.*)", 3)
If IsArray($aTmp) Then
$sUrl = $aTmp[0]
Else
ExitLoop
EndIf
$oReq.Open('GET', $sUrl, False)
EndSwitch
$oReq.SetRequestHeader('User-Agent', $sUserAgent)
$oReq.SetRequestHeader('Cache-Controle', 'no-cach')
If $Cookie <> "" Then $oReq.SetRequestHeader('Cookie', $Cookie)
$oReq.SetRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
$oReq.SetRequestHeader('Accept-Language', 'ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3')
$oReq.SetRequestHeader('Connection', 'keep-alive')
$sSendStr = "st.redirect=&st.asr=&st.posted=set&st.originalaction=http%3A%2F%2Fwww.odnoklassniki.ru%2Fdk%3Fcmd%3DAnonymLogin%26st.cmd%3DanonymLogin&st.fJS=enabled&st.st.screenSize=1366+x+768&st.st.browserSize=656&st.st.flashVer=11.9.900&st.email=" & encodeURIComponent($email) & "&st.password=" & encodeURIComponent($password) & "&st.remember=on&st.iscode=false"
$oReq.Send($sSendStr)
$GetAllResponseHeaders = $oReq.GetAllResponseHeaders()
If StringInStr($GetAllResponseHeaders, "Set-Cookie:") Then
$SetCookie = $oReq.GetResponseHeader("Set-Cookie")
$Cookie = _SetCookieParse($GetAllResponseHeaders)
EndIf
$ResponseText = $oReq.ResponseText
Next
$oError = 0
EndFunc ;==>_ok_login
; ========== end public functions ========== ;
; ========== private functions ========== ;
Func ErrorFunc()
;//MsgBox(16, 'COM Error', $oError.description)
;//Exit 2
Return SetError(2, 0, 0)
EndFunc ;==>ErrorFunc
Func encodeURIComponent($sTxt)
Return $oSC.Eval('encodeURIComponent("' & $sTxt & '");')
EndFunc ;==>encodeURIComponent
Func decodeURIComponent($sTxt)
Return $oSC.Eval('decodeURIComponent("' & $sTxt & '");')
EndFunc ;==>decodeURIComponent
Func _SetCookieParse($AllResponseHeaders)
Local $sCOOKIES = ""
Local $iOffset = 1, $iError = 0
While $iError = 0
$aTmp = StringRegExp($AllResponseHeaders, "(?si)Set-Cookie:([^=]+)=([^;]+)", 2, $iOffset)
$iError = @error
$iOffset = @extended
If $iError = 0 Then
$sCOOKIES &= $aTmp[1] & ": " & $aTmp[2] & "; "
Else
ExitLoop
EndIf
WEnd
$sCOOKIES = StringTrimRight($sCOOKIES, 2)
$sCOOKIES = StringStripWS($sCOOKIES, 1 + 2 + 4)
Return $sCOOKIES
EndFunc ;==>_SetCookieParse
; ========== end private functions ========== ;
$sUserAgent = 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.12'
$email = "login"
$password = "pass"
$oReq = ObjCreate('WinHttp.WinHttpRequest.5.1')
If Not IsObj($oReq) Then
Exit
EndIf
$sSendStr = 'fr.posted=set&fr.needCaptcha=&fr.login=' & encodeURIComponent($email) & '&fr.password=' & encodeURIComponent($password) & '&button_login=Войти'
$oReq.Open('POST', 'https://m.ok.ru/dk?bk=GuestMain&st.cmd=main&_prevCmd=main&tkn=9927', False)
$oReq.SetRequestHeader('User-Agent', $sUserAgent)
$oReq.SetRequestHeader('Host', 'm.ok.ru')
$oReq.SetRequestHeader('Accept', 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1')
$oReq.SetRequestHeader('Accept-Language', 'ru-RU,en;q=0.9,ru;q=0.8')
$oReq.SetRequestHeader('Accept-Encoding', 'gzip, deflate')
$oReq.SetRequestHeader('Referer', 'http://m.ok.ru')
$oReq.SetRequestHeader('Cookie', 'DCAPS=dpr%5E1%7Cvw%5E1241%7Csw%5E1280%7C')
$oReq.SetRequestHeader('Cookie2', '$Version=1')
$oReq.SetRequestHeader('Connection', 'Keep-Alive')
$oReq.SetRequestHeader('Content-Length', StringLen($sSendStr))
$oReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
$oReq.Send($sSendStr)
$sHeaders = $oReq.GetAllResponseHeaders()
$sCookies = _GetCookies($sHeaders)
$sLocation = StringRegExpReplace($sHeaders, '(?si).*Location: ([^\r\n]+).*', '\1')
$sJSESSIONID = StringRegExpReplace($sLocation, '(?si).*;jsessionid=(.*?)\?st.*', '\1')
$oReq.Open('GET', $sLocation, False)
$oReq.SetRequestHeader('User-Agent', $sUserAgent)
$oReq.SetRequestHeader('Host', 'm.ok.ru')
$oReq.SetRequestHeader('Accept', 'text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1')
$oReq.SetRequestHeader('Accept-Language', 'ru-RU,en;q=0.9,ru;q=0.8')
$oReq.SetRequestHeader('Referer', 'http://m.ok.ru')
$oReq.SetRequestHeader('Cookie', 'aftakampl0=field_login#' & $email & '; ' & $sCookies)
$oReq.SetRequestHeader('Cookie2', '$Version=1')
$oReq.SetRequestHeader('Connection', 'Keep-Alive')
$oReq.Send()
ConsoleWrite($oReq.ResponseText & @LF)
Func _GetCookies($sHeaders)
Local $aCookies = StringRegExp($sHeaders, 'Set-Cookie: ([^\r\n]+)', 3)
Local $sCookies = ''
For $i = 0 To UBound($aCookies)-1
$sCookies &= $aCookies[$i] & '; '
Next
Return $sCookies
EndFunc
Func encodeURIComponent($sURLString)
$sURLString = BinaryToString(StringToBinary($sURLString), 4)
Local $aURLStrSplit = StringSplit($sURLString, "")
Local $sRetString = ""
For $i = 1 To UBound($aURLStrSplit) - 1
If Not StringRegExp($aURLStrSplit[$i], '(?i)[a-z]|\.|-|_') Then
$aURLStrSplit[$i] = "%" & Hex(Asc($aURLStrSplit[$i]), 2)
EndIf
$sRetString &= $aURLStrSplit[$i]
Next
Return $sRetString
EndFunc