Not sure what I'm doing wrong but I am having difficulties using WebClient.
No problems with HttpWebRequest but I am not sure how to access the DOM with
MSHtml...
This is what I'm trying with WebClient:
Dim Client As New WebClient()
Client.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
Client.DownloadData("
https://website...")
Client.Headers.Add("Cookie", Client.ResponseHeaders("Set-Cookie"))
Dim Data() As Byte = Client.UploadData("
https://website...", "POST",
Encoding.UTF8.GetBytes("postdatahere"))
Dim thisstring As String
thisstring = Encoding.UTF8.GetString(Data)
Client.Dispose()
MsgBox(Encoding.UTF8.GetString(Data))
It seems as if the cookie isn't being retained properly, here is what works
for me using HttpWebRequest:
Dim myWebRequest As HttpWebRequest =
CType(WebRequest.Create(
https://website...), HttpWebRequest)
Dim WebResponse As HttpWebResponse
Dim srReader As StreamReader
Dim swWriter As StreamWriter
Dim strPostData As String
Dim strResponse As String
Dim myMSHTML As mshtml.HTMLDocument
Dim myDoc As mshtml.IHTMLDocument2
myWebRequest.CookieContainer = New CookieContainer
WebResponse = myWebRequest.GetResponse
strPostData = "POST data"
myWebRequest = CType(WebRequest.Create(
https://website...), HttpWebRequest)
myWebRequest.Method = "POST"
myWebRequest.ContentLength = strPostData.length
myWebRequest.ContentType = "Content-Type: application/x-www-form-urlencoded"
myWebRequest.CookieContainer = New CookieContainer
swWriter = New StreamWriter(myWebRequest.GetRequestStream)
swWriter.Write(strPostData)
swWriter.Close()
WebResponse = myWebRequest.GetResponse
srReader = New StreamReader(WebResponse.GetResponseStream)
strResponse = srReader.ReadToEnd
srReader.Close()
here's where i start to run into problems with HttpWebRequest though:
myDoc = New mshtml.HTMLDocument
myDoc.clear()
myDoc.write(strResponse)
myDoc.close()