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 :)

Code:

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:1.9.2.3) 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)
            postreqstream.Close()
            Dim postresponse As HttpWebResponse
            postresponse = DirectCast(postreq.GetResponse, HttpWebResponse)
            tempcookies.Add(postresponse.Cookies)
            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!")
            Else
                MsgBox("Logged in", 0, "Success!")
            End If
        End Sub
    End Class

bump

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.