Jump to content

Problem with Gmail login Winhttp and cookies


blityon
 Share

Recommended Posts

Hi, I have much time reading this forum, I have read and seen many examples and I've learned a lot, but this time I have not been able to continue, does anyone could help me?

I can not do login into gmail, I have an error in cookies.

Posted Image

Posted Image

Thanks :graduated:

#include "WinHttp.au3"
$User = "Your user name"
$Pass = "Your password"
; GMAIL 1
; *******
$session=_winhttpopen("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729")
$connect=_winhttpconnect($session,'www.google.com',$INTERNET_DEFAULT_HTTPS_PORT)
$request=_winhttpopenrequest($connect, Default,'accounts/ServiceLoginBoxAuth', Default,'https://www.google.com',"",$WINHTTP_FLAG_SECURE)
_WinHttpSendRequest($request)
_WinHttpReceiveResponse($request)
$cookie = StringStripWS(Getcookie($request), 7)
$CookieInicio = $cookie
;~ ConsoleWrite($CookieInicio & @CRLF)
ConsoleWrite("-INICIO---------------------------------" & @CRLF)
$Cabeceras =_WinHttpQueryHeaders($request)
ConsoleWrite($Cabeceras & @CRLF)
ConsoleWrite("-FIN------------------------------------" & @CRLF)
ConsoleWrite("-COOKIES--------------------------------" & @CRLF)
ConsoleWrite($cookie & @CRLF)
ConsoleWrite("-FIN-COOKIES----------------------------" & @CRLF)
$sData = ""
If _WinHttpQueryDataAvailable($request) Then
While 1
  $sChunk = _WinHttpReadData($request)
  If @error Then ExitLoop
  $sData &= $sChunk
WEnd
EndIf
$File = FileOpen("Gmail1.html", 2)
FileWriteLine($File, $sData)
FileClose($File)
$Galx = StringRegExp($cookie, "GALX=(.*?);", 2)
; GMAIL 2
; *******
$connect=_winhttpconnect($session,'www.google.com',$INTERNET_DEFAULT_HTTPS_PORT)
$request=_winhttpopenrequest($connect, Default,'accounts/ServiceLoginBoxAuth?Email=' & $User & '&Passwd=' & $Pass & '&GALX=' & $Galx[1], Default,'https://www.google.com',"",$WINHTTP_FLAG_SECURE)
_WinHttpAddRequestHeaders($request, 'Cookie: ' & $cookie)
_WinHttpAddRequestHeaders($request, 'Content-Type: application/x-www-form-urlencoded')
_WinHttpAddRequestHeaders($request, 'Connection: Keep-Alive')
_WinHttpAddRequestHeaders($request, 'Accept: */*')
_WinHttpAddRequestHeaders($request, 'Accept-Language: es-es')
_WinHttpSendRequest($request)
$Respuesta = _WinHttpReceiveResponse($request)
$cookie = StringStripWS(Getcookie($request), 7)& @CRLF & $CookieInicio
ConsoleWrite("-INICIO---------------------------------" & @CRLF)
$Cabeceras =_WinHttpQueryHeaders($request)
ConsoleWrite($Cabeceras & @CRLF)
ConsoleWrite("-FIN------------------------------------" & @CRLF)
ConsoleWrite("-COOKIES--------------------------------" & @CRLF)
ConsoleWrite($cookie & @CRLF)
ConsoleWrite("-FIN-COOKIES----------------------------" & @CRLF)
$sData = ""
If _WinHttpQueryDataAvailable($request) Then
While 1
  $sChunk = _WinHttpReadData($request)
  If @error Then ExitLoop
  $sData &= $sChunk
WEnd
EndIf
$File = FileOpen("Gmail2.html", 2)
FileWriteLine($File, $sData)
FileClose($File)
Func GetCookie($request)
    $Cabeceras =_WinHttpQueryHeaders($request)
$CookieF = ""
$CookieT = ""
$ArrayCookies = StringSplit($Cabeceras, @CRLF)
For $b = 0 To UBound($ArrayCookies) - 1
  If StringInStr($ArrayCookies[$b], "Set-Cookie:") Then
   $CookieT = StringReplace($ArrayCookies[$b], "Set-Cookie: ", "")
   $CookieF = $CookieF & $CookieT & @CRLF
  EndIf
Next
Return $CookieF
EndFunc
Edited by blityon
Link to comment
Share on other sites

Thank you for responding, I had already seen these websites and examples (and all post your own). But these urls add anything to my project, they use the Google API which is very limited.

I want to access gmail from google accounts. But I have some problem with the cookies. I can pick it and I can send the cookie, but something I'm doing wrong at this point.

If you think you can help, I'd be very grateful.

I used IE.au3 and works perfectly, but IE.au3 UDF is much slower.

I'm trying to get the HTML source code of more than 1 million messages.

Edited by blityon
Link to comment
Share on other sites

Thank you for responding, I had already seen these websites and examples (and all post your own). But these urls add anything to my project, they use the Google API which is very limited.

I want to access gmail from google accounts. But I have some problem with the cookies. I can pick it and I can send the cookie, but something I'm doing wrong at this point.

If you think you can help, I'd be very grateful.

I used IE.au3 and works perfectly, but IE.au3 UDF is much slower.

I'm trying to get the HTML source code of more than 1 million messages.

One... Hundred... billion messages! (Dr. Evil)

Use _WinHttpSimpleFormFill then. Anything you can do with IE regarding forms, you can do with that function too.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Thanks, I had done tests _WinHttpSimpleFormFill, but this did not work.

Using the browser, I can enter https://mail.google.com/mail/u/0/x/gdlakb-/gp/

I also tried _WinHttpSimpleFormFill with:

https://mail.google.com/mail/u/0/x/

https://accounts.google.com/ServiceLogin

http://www.gmail.com

https://mail.google.com/mail/u/0/h/

#include <WinHttp.au3>
$User = "Your user"
$Pass = "Your pass"
; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, "mail.google.com")
; Fill form on this page
$sRead = _WinHttpSimpleFormFill($hConnect, "mail/u/0/x/gdlakb-/gp/", "index:0", "name:Email", $User, "name:Passwd", $Pass)
;Close connection handle
_WinHttpCloseHandle($hConnect)
; Close session handle
_WinHttpCloseHandle($hOpen)
;Print returned:
ConsoleWrite($sRead & @CRLF)
Edited by blityon
Link to comment
Share on other sites

Thanks, I had done tests _WinHttpSimpleFormFill, but this did not work.

Using the browser, I can enter https://mail.google.com/mail/u/0/x/gdlakb-/gp/

I also tried _WinHttpSimpleFormFill with:

https://mail.google.com/mail/u/0/x/

https://accounts.google.com/ServiceLogin

http://www.gmail.com

https://mail.google.com/mail/u/0/h/

#include <WinHttp.au3>
$User = "Your user"
$Pass = "Your pass"
; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, "mail.google.com")
; Fill form on this page
$sRead = _WinHttpSimpleFormFill($hConnect, "mail/u/0/x/gdlakb-/gp/", "index:0", "name:Email", $User, "name:Passwd", $Pass)
;Close connection handle
_WinHttpCloseHandle($hConnect)
; Close session handle
_WinHttpCloseHandle($hOpen)
;Print returned:
ConsoleWrite($sRead & @CRLF)

Function first tries sending the form using usual protocols and if that fails it uses WINHTTP_FLAG_SECURE.

Google in this case says that either will work, which is not correct.

If you open WinHttp.au3 you will see lines

Local $hRequest = __WinHttpFormSend($hInternet, $sMethod, $sAction, $fMultiPart, $sBoundary, $sAddData)
If _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_STATUS_CODE) > $HTTP_STATUS_BAD_REQUEST Then
_WinHttpCloseHandle($hRequest)
$hRequest = __WinHttpFormSend($hInternet, $sMethod, $sAction, $fMultiPart, $sBoundary, $sAddData, True) ; try adding $WINHTTP_FLAG_SECURE
EndIf

... inside _WinHttpSimpleFormFill(). If you force that first __WinHttpFormSend() to use $WINHTTP_FLAG_SECURE by adding new parameter set to "true" then it should work.

I could add option to force behavior for _WinHttpSimpleFormFill(). Will see.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...