HttpWebRequest Post...

TeachMe

Member
Joined
Jun 27, 2012
Messages
16
Programming Experience
Beginner
I am a member of a forum that allows for a BUY/SELL/TRADE section where I'd like to make a couple posts a week. I'd like to use the interface of my VB.NET application to post there.


I learned how to login to a the Rocbattl.com forum which was pretty easy to do. Here is the login string that I found in LiveHttpHeaders:


"http://rocbattle.com/check_login.php?pg=http://rocbattle.com/index.php"


And here is the post string for logging in through this request:


"username=acebeats1&password=Jordan123&remember=remember&login=: undefined"


But I don't know what to do after I login. I'm trying to create a POST to this section of the forum (BUY/SELL/TRADE): http://rocbattle.com/viewforumrb.php?f=16&sid=3767e7ef319b85e69321fe2c3c92b499


So I guess my question would be; how do I carry the login cookie & submit a new post to the "BUY/SELL/TRADE" section?


HERE IS THE CODE THAT I'M USING SO FAR:
VB.NET:
Imports System.IO
Imports System.Net
Imports System.Text


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim postData As String = "username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&remember=remember&login=: undefined"
        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)
        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://rocbattle.com/check_login.php?pg=http://rocbattle.com/index.php"), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "http://rocbattle.com/check_login.php?pg=http://rocbattle.com/index.php"
        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.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


        'Webbrowser show results:
        WebBrowser1.DocumentText = thepage
    End Sub
Again, the code above successfully logs me in, but I'm not sure how to POST & create a new thread to the following link:


http://rocbattle.com/viewforumrb.php?f=16&sid=3767e7ef319b85e69321fe2c3c92b499






Here is what the POST string looks like according to LiveHTTPHeaders:


subject=MY+SUBJECT&addbbcode20=100&helpbox=Tip%3A+Styles+can+be+applied+quickly+to+selected+text.&message=MY+BODY+MESSAGE%3F&attach_sig=on&lastclick=1504576612&post=Submit&creation_time=1504576612&form_token=7b51dd142acd764e07f198589e3dc1cc360a8664: undefined




I also noticed that the POST STRING requires the following 3:

lastclick=
creation_time=
form_token=




And I can see that they all exist & are generated on the main thread posting page within the HTML:


http://rocbattle.com/viewforumrb.php?f=16&sid=3767e7ef319b85e69321fe2c3c92b499




How do I extract these values with the HttpWebRequest & POST it to this section of the forum? Thanks for any support.
 
Top Bottom