VB.NET HttpWebRequest - 发布到论坛

时间:2017-09-04 14:19:57

标签: vb.net post httpwebrequest

我想知道你是否可以帮我解决这个问题" HttpWebRequest"。

我学会了如何登录一个非常容易的论坛。这是我在LiveHttpHeaders中找到的登录字符串:

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

以下是通过此请求登录的帖子字符串:

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

但我登录后不知道该怎么做。我试图在论坛的这一部分创建一个POST(买/卖/交易): 的 http://rocbattle.com/viewforumrb.php?f=16&sid=3767e7ef319b85e69321fe2c3c92b499

所以我想我的问题是;我如何携带登录cookie&向"买入/卖出/交易"提交新帖子部?

这是我使用的代码:

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

0 个答案:

没有答案