0

好的,所以我正在尝试制作一个程序,该程序将登录到 [b]my [/b] 站点,机器人/软件将我登录,但是当我移动到我的 rpg 中的任何其他页面时,它会将我注销,我认为是因为我重置了让我登录的 cookie。

所以这是我的登录按钮的代码

Public Class Form1
    Dim logincookie As CookieContainer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim postData As String = "username=" & TextBox2.Text & "&password=" & TextBox1.Text & "&submit=Login"
        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://www.myurl.net/login.php?tid="), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "http://www.myurl.net/login.php?tid="
        postReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0.1"
        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

    End Sub

注意顶部的 Dim logincookie As CookieContainer....

一切都很完美(它让我登录)然后我现在有另一个按钮来测试我是否可以提交一个基本的 html 表单

这是那个按钮代码

 Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://myurl.net/signature.php"), HttpWebRequest)
        request.CookieContainer = logincookie
        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim theusercp As String = reader.ReadToEnd

        RichTextBox2.Text = theusercp
    End Sub

注意我没有在这个顶部声明 Dim logincookie As CookieContainer 可能是我出错了?在我单击第二个按钮并且这段代码处于活动状态后,它会将我注销...我认为是我在重置登录 cookie 吗?或者也许没有设置正确?

我试图让用户可以通过这个 exe 登录到我的网站并在那里更新 sig 等...

PS这两个按钮都会将html提交给我,这样我就可以看到注销了

4

0 回答 0