Hello, this is my first foray into the world of web programming, and none of
the searching I've done to solve this problem has left me any the wiser, so
I hope someone out there can help...
What I'm trying to do:
There is a turn based strategy game I play that has a web interface. I want
to write a tool to check my status webpage every so often to see if I have
new turns to play, and go 'beep' and briefly show a pop up if I do - just
like many email clients do with new mail.
Progress so far:
After a bit of Googling and looking at the MSDN I've written a simple method
which will return the source code of a bog standard web page (code below).
Where I got stuck:
The web interface for the game requires me to login. Once logged in,
persistent cookies keep me logged on until I specifically logout. I was
hoping that after logging on in the usual way my method would return the
HTML for my game status page, however instead all I get is the source for
the login page.
Help!:
How do I use cookies so that my application is logged in, and gives me the
source of the page I want? Is this even what I need to do? Or how do I
login fresh each time then get the source? All advice gratefully received.
' Returns HTML source of 'sUrl'.
Public Function Fetch(ByVal sUrl As String) As String
Dim s As String ' Storage for the HTML
Dim buf(8192) As Byte ' Buffer for stream reads
Dim req As HttpWebRequest = CType(WebRequest.Create(sUrl),
HttpWebRequest)
Dim resp As HttpWebResponse = CType(req.GetResponse(),
HttpWebResponse)
Dim respStream As Stream = resp.GetResponseStream()
Dim tempString As String
Dim count As Integer = 0
Do
count = respStream.Read(buf, 0, buf.Length)
If count <> 0 Then
tempString = Encoding.ASCII.GetString(buf, 0, count)
s = s & tempString
End If
Loop While count > 0
Return s
End Function
|