我已经完成了这个项目。我需要在工作时登录我的服务器,然后在不同的页面上提交表单。如何使登录连接保持活动状态,然后发布第二个表单或网址?
Dim postData As String = "Username=system&Password=system&Action=Srh-1-1&Go=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("MY SERVER URL"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.Referer = "MY SERVER URL"
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
所以,登录工作正常。但是,再次,我现在如何发布到不同的表单,或将整个表单+提交详细信息加载到URL?我需要在登录后发布数据并提交表单。表单将返回我将解析的数据。基本上,所有这一切都可以手动完成,但这个程序将通过自动登录,提交和解析来节省我的时间。