1

Hey whhat's up. I've been looking at some example source codes but I can't quite figure it out. I'd like to send a POST request to login to a website with my account. For an example, how would I login to this website using HttpWebRequest..

http://z4.invisionfree.com/cotec/index.php?

It's for an application I'm building for my clan where you have to have an account on the forum to open the application, so if the login works it opens.

3 Answers 3

3

There's a decent tutorial for HTTPWebRequest POST methods and a login example here: http://howtostartprogramming.com/vb-net/vb-net-tutorial-51-httpwebrequest-post-method/

Sign up to request clarification or add additional context in comments.

Comments

2
dim email as string = "your email"
dim pass as string = "your pass"

    Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://touch.facebook.com"), HttpWebRequest)
                postReq.Method = "GET"
                postReq.KeepAlive = True
                postReq.CookieContainer = logincookie
                postReq.ContentType = "application/x-www-form-urlencoded"
                postReq.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3"

                Dim postresponse As HttpWebResponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
                logincookie.Add(postresponse.Cookies)

                Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

                Dim infos As String = postreqreader.ReadToEnd

                '---------------------------

                Dim byteData As Byte() = encoding.GetBytes("lsd=&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&version=1&ajax=0&width=0&pxr=0&gps=0&m_ts=&li=&email=" & email.Replace("@", "%40") & "&pass=" & pass & "&login=Connexion")

                postReq = DirectCast(WebRequest.Create("https://touch.facebook.com/login.php?refsrc=https%3A%2F%2Ftouch.facebook.com%2F&refid=8"), HttpWebRequest)
                postReq.Method = "POST"
                postReq.KeepAlive = True
                postReq.CookieContainer = logincookie
                postReq.ContentType = "application/x-www-form-urlencoded"
                postReq.Referer = "https://touch.facebook.com/"
                postReq.UserAgent = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3"
                postReq.ContentLength = byteData.Length

                Dim postreqstream As Stream = postReq.GetRequestStream()
                postreqstream.Write(byteData, 0, byteData.Length)
                postreqstream.Close()

                postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
                logincookie.Add(postresponse.Cookies)

                postreqreader = New StreamReader(postresponse.GetResponseStream())

Comments

1

Why not leverage this bit of code to simplify your effort: http://joel.net/code/easyhttp.aspx

2 Comments

So how would I use the class to send a login request? EasyHttp.Send("z4.invisionfree.com/cotec/index.php?", "username=USER&password=PASS") Just that?
You could yes. Just make sure that whatever the form fields are named you specify them in the fashion you show.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.