Hi Trying to login to google accounts this is the code that I created but I get this error:

Your browsers cookie functionality is turned off. Please turn it on.

I dont want to use there api too as this is a learning for me thought I had it nailed till this error

Please help thanks :)


Imports System.IO, System.Net, System.Text
    Imports System.Text.RegularExpressions

    Public Class CookieExample
        Dim logincookie As CookieContainer

        Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
            Dim postData As String = "continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dheader%26nomobiletemp%3D1%26hl%3Den_GB%26next%3D%252F&service=youtube&uilel=3&dsh=-1380775512271390978&ltmpl=sso&hl=en_GB&GALX=fZFkoccMVwk&pstMsg=1&dnConn=&checkConnection=youtube%3A487%3A1&checkedDomains=youtube&timeStmp=&secTok=&Email=" & txtUser.Text & "&Passwd=" & txtPass.Text & "&signIn=Sign+in&PersistentCookie=yes&rmShown=1"
            Dim tempcookies As New CookieContainer
            Dim encoding As New UTF8Encoding
            Dim byteData As Byte() = encoding.GetBytes(postData)
            Dim postreq As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://accounts.google.com/ServiceLoginAuth"), HttpWebRequest)
            postreq.Method = "POST"
            postreq.KeepAlive = True
            postreq.CookieContainer = tempcookies
            postreq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv: Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729"
            postreq.ContentType = "application/x-www-form-urlencoded"
            postreq.Referer = "https://accounts.google.com/ServiceLogin?uilel=3&service=youtube&passive=true&continue=http%3A%2F%2Fwww.youtube.com%2Fsignin%3Faction_handle_signin%3Dtrue%26feature%3Dheader%26nomobiletemp%3D1%26hl%3Den_GB%26next%3D%252F&hl=en_GB&ltmpl=sso"
            postreq.ContentLength = byteData.Length
            Dim postreqstream As Stream = postreq.GetRequestStream()
            postreqstream.Write(byteData, 0, byteData.Length)
            Dim postresponse As HttpWebResponse
            postresponse = DirectCast(postreq.GetResponse, HttpWebResponse)
            logincookie = tempcookies
            Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
            Dim thepage As String = postreqreader.ReadToEnd
            RichTextBox1.Text = thepage
            If thepage.Contains("logout") = True Then
                MsgBox("Incorrect Username/password combination", 0, "Login error!")
                MsgBox("Logged in", 0, "Success!")
            End If
        End Sub
    End Class
6 Years
Discussion Span
Last Post by mr3army
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.