[2005] HTTP GET Method to a website with Cookie header
I am trying to access a website using vb.net. I need to change a couple of headers (mainly the Cookie header). Then I need to get all the HTML contents of the page into one HTML file. How do I go about doing this? I've had problems making it work with HttpWebResponse and using a stream. It keeps telling me that the stream can't be read. It also has problems using GET instead of POST. Can someone help me out?
Re: [2005] HTTP GET Method to a website with Cookie header
Re: [2005] HTTP GET Method to a website with Cookie header
Can you post the code in question?
Re: [2005] HTTP GET Method to a website with Cookie header
here is the code :
VB Code:
Dim web1 As HttpWebRequest = CType(WebRequest.Create("http://www.somesite.com/page.php"), HttpWebRequest)
Dim myHttpWebResponse As HttpWebResponse
web1.AllowAutoRedirect = False
web1.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
web1.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*"
web1.Headers.Add(HttpRequestHeader.AcceptLanguage, "bg")
web1.KeepAlive = True
web1.Headers.Add(HttpRequestHeader.Cookie, "PHPSESSID=d2b09d04a99bd4e222e13766229ece19")
web1.ContentType = "application/x-www-form-urlencoded"
web1.Method = "GET"
myHttpWebResponse = CType(web1.GetResponse(), HttpWebResponse)
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse) 'Error here Message: Stream was not readable
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
strHTML = strHTML & outputData
count = streamRead.Read(readBuff, 0, 256)
End While
streamRead.Close()
streamResponse.Close()
myHttpWebResponse.Close()
all i want to do is access that page and get its HTML contents, but i want to set the PHPSESSID before i access the page. What do i do? Do I use get or is there something wrong with my code? Please help. Thx
Re: [2005] HTTP GET Method to a website with Cookie header
a reply with some help would be nice
Re: [2005] HTTP GET Method to a website with Cookie header
did i miss something? cause all of a sudden nobody is helping me out in these forums.
Re: [2005] HTTP GET Method to a website with Cookie header
Have you tried doing the following?
Code:
WebRequest.Create("http://www.somesite.com/page.php?PHPSESSID=d2b09d04a99bd4e222e13766229ece19")
You should be able to remove all that web1 configuration code too.
This should work for a standard GET request.