Vb.net 在httpwebrequest期间获取所有表单元素--需要帮助

Vb.net 在httpwebrequest期间获取所有表单元素--需要帮助,vb.net,Vb.net,我试图做的是创建一个httpwebrequest并导航到一个网站,比如说一个需要用户在网站上创建用户名和密码的网站。我知道我可以使用Firefoxs插件LiveHeaders并填写从标题中捕获帖子的表单 从本节中,我可以找到用户名和密码的位置,并用以下变量替换用户名和密码: Dim postData As String = "referer=http%3A%2F%2Fforums.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3Dglobal%26sec

我试图做的是创建一个httpwebrequest并导航到一个网站,比如说一个需要用户在网站上创建用户名和密码的网站。我知道我可以使用Firefoxs插件LiveHeaders并填写从标题中捕获帖子的表单

从本节中,我可以找到用户名和密码的位置,并用以下变量替换用户名和密码:

Dim postData As String = "referer=http%3A%2F%2Fforums.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3Dglobal%26section%3Dlogin&username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&rememberMe=1"
我正在尝试或需要弄清楚的是,如何在向网站发出请求的过程中获取这些输入,而不是必须输入信息、捕获标题,然后为帖子手动编辑它们

我已经连续阅读了大约两周了,我似乎找不到一个解决方案来解决人们如何导航到一个网站……发出请求(可以是httpwebrequest或webrequest)提取网站的所有表单输入元素,并将它们打印/获取到字符串中,然后将字符串读取到richtextbox中

Imports System.Net
Imports System.Text
Imports System.IO

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 = "referer=http%3A%2F%2Fforums.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3Dglobal%26section%3Dlogin&username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&rememberMe=1"
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)

Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create(Textbox1.text), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = TextBox1.Text
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

RichTextBox1.Text = thepage
此代码将导航到加载到textbox1中的网站,并将html代码读入富文本框

但是……通过阅读上面关于以下内容的回答:

For Each key As String In HttpContext.Current.Request.Form.Keys
Dim value as string = HttpContext.Current.Request.Form(key)
Next
这段代码在我的应用程序中任何地方都不起作用。我得到一个错误代码:

未声明“HttpContext”。由于其保护级别,可能无法访问


总之,在请求过程中,使用上述方法的用户如何获取网站的所有表单输入元素?

您是否使用HtmlAlityPack解决了此问题,或者这仍然是一个问题?