Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

using a webbrequest to do functions in webbrowser

$
0
0
INFO:
i have a webrequest that i would like to impliment into my program that will do a function on my website but sending the webrequest alone doesnt work and also sending a login request errors with: "cookie functionality is turned off. Please turn it on.", so I added a webbrowser and now I want the webrequest to work along side the webbrowser, but i dont think it is because everytime i send the request the source of the webrequest prompts me to re-signin

MY REQUEST:

Dim postData As String = "[mydata]"
Dim tempCookies As New CookieContainer
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(postData)

Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("[mywebpage]"), HttpWebRequest)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.CookieContainer = tempCookies
postReq.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
postReq.Referer = ("[mywebpage]")
postReq.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"
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

Viewing all articles
Browse latest Browse all 27349

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>