Asynchronous HttpWebRequest?

littlebigman

Well-known member
Joined
Jan 5, 2010
Messages
75
Programming Experience
Beginner
Hello

I noticed that HttpWebRequest freezes the UI while it's waiting for a web page to be downloaded:

VB.NET:
Dim Request As HttpWebRequest

MsgBox("Before GetResponse")
Response = Request.GetResponse()
MsgBox("After GetResponse")
[code]

If someone's done this before, what is a good way to keep the application responsive?

Thank you.
 
The corresponding async call for GetResponse is BeginGetResponse. WebClient is a helper class for common WebRequest operations, and it generally easier to use, it's events for the Async calls are also safe to use in UI thread and thus easier to handle than the Begin-methods callbacks.
 
I'm close to solving this issue, but as a newbie, I'm stuck at how to retrieve cookies from the download/callback function once it's done and I'm back in the Form1 calling code.

I need to get the cookies back because the site I'm downloading pages from requires authentication, and sends a session ID as a cookie.

Here's the code I'm using:

pastebin - Something - post number 1796233

If someone's done this before, I'd appreciate it if you could tell how to do this.

Thank you.

Edit: Solved the issue by moving the HTTP part from its own class into the Form1 class.
 
Last edited:
Back
Top