EDN Admin
Well-known member
Im trying to do a POST request but the website tells me that cookies are not enabled on my browser.
This is what Im using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim cookie <span style="color:Blue; As CookieContainer
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
<span style="color:Blue; Dim tempCookies <span style="color:Blue; As <span style="color:Blue; New CookieContainer
<span style="color:Blue; Dim postData <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=YhfWS&email=" & TextBox1.Text & <span style="color:#A31515; "&pass=" & TextBox2.Text & <span style="color:#A31515; "&persistent=1&default_persistent=1&login=Login"
<span style="color:Blue; Dim encoding <span style="color:Blue; As <span style="color:Blue; New UTF8Encoding
<span style="color:Blue; Dim byteData <span style="color:Blue; As <span style="color:Blue; Byte() = encoding.GetBytes(postData)
<span style="color:Blue; Dim postReq <span style="color:Blue; As HttpWebRequest = HttpWebRequest.Create(<span style="color:#A31515; "https://login.facebook.com/login.php?login_attempt=1")
postReq.CookieContainer = tempCookies
postReq.Method = <span style="color:#A31515; "POST"
postReq.KeepAlive = <span style="color:Blue; True
postReq.ContentType = <span style="color:#A31515; "application/x-www-form-urlencoded"
postReq.UserAgent = <span style="color:#A31515; "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"
postReq.Referer = <span style="color:#A31515; "https://login.facebook.com/login.php?login_attempt=1"
postReq.ContentLength = byteData.Length
<span style="color:Blue; Dim postreqstream <span style="color:Blue; As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
<span style="color:Blue; Dim postresponse <span style="color:Blue; As HttpWebResponse
postresponse = <span style="color:Blue; DirectCast(postReq.GetResponse(), HttpWebResponse)
tempCookies.Add(postresponse.Cookies)
cookie = tempCookies
<span style="color:Blue; Dim postreqreader <span style="color:Blue; As <span style="color:Blue; New StreamReader(postresponse.GetResponseStream())
<span style="color:Blue; Dim src <span style="color:Blue; As <span style="color:Blue; String = postreqreader.ReadToEnd
RichTextBox1.Text = src
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
I used WebBrowser1.DocumentText = RichTextBox1.Text to check if Im logged in or not, but it shows me that cookies are not enabled.
How do I get it working?
View the full article
This is what Im using:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim cookie <span style="color:Blue; As CookieContainer
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
<span style="color:Blue; Dim tempCookies <span style="color:Blue; As <span style="color:Blue; New CookieContainer
<span style="color:Blue; Dim postData <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=YhfWS&email=" & TextBox1.Text & <span style="color:#A31515; "&pass=" & TextBox2.Text & <span style="color:#A31515; "&persistent=1&default_persistent=1&login=Login"
<span style="color:Blue; Dim encoding <span style="color:Blue; As <span style="color:Blue; New UTF8Encoding
<span style="color:Blue; Dim byteData <span style="color:Blue; As <span style="color:Blue; Byte() = encoding.GetBytes(postData)
<span style="color:Blue; Dim postReq <span style="color:Blue; As HttpWebRequest = HttpWebRequest.Create(<span style="color:#A31515; "https://login.facebook.com/login.php?login_attempt=1")
postReq.CookieContainer = tempCookies
postReq.Method = <span style="color:#A31515; "POST"
postReq.KeepAlive = <span style="color:Blue; True
postReq.ContentType = <span style="color:#A31515; "application/x-www-form-urlencoded"
postReq.UserAgent = <span style="color:#A31515; "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"
postReq.Referer = <span style="color:#A31515; "https://login.facebook.com/login.php?login_attempt=1"
postReq.ContentLength = byteData.Length
<span style="color:Blue; Dim postreqstream <span style="color:Blue; As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
<span style="color:Blue; Dim postresponse <span style="color:Blue; As HttpWebResponse
postresponse = <span style="color:Blue; DirectCast(postReq.GetResponse(), HttpWebResponse)
tempCookies.Add(postresponse.Cookies)
cookie = tempCookies
<span style="color:Blue; Dim postreqreader <span style="color:Blue; As <span style="color:Blue; New StreamReader(postresponse.GetResponseStream())
<span style="color:Blue; Dim src <span style="color:Blue; As <span style="color:Blue; String = postreqreader.ReadToEnd
RichTextBox1.Text = src
<span style="color:Blue; End <span style="color:Blue; Sub
[/code]
I used WebBrowser1.DocumentText = RichTextBox1.Text to check if Im logged in or not, but it shows me that cookies are not enabled.
How do I get it working?
View the full article