HTTPWebRequest (Asynchronous Operation)

G

Guest

Below is the code that I use to upload large files from my web server virtual
directory. This code locks up my application for quite a while when a large
file is moving. What modifications will allow this code to execute in a
asynchronous manner?

Function GetImageFromURL(ByVal url As String) As Byte()
Dim wr As HttpWebRequest = DirectCast(WebRequest.Create(url),HttpWebRequest)
If Not ProxyObject Is Nothing Then wr.Proxy = ProxyObject
Dim wresponse As HttpWebResponse = DirectCast(wr.GetResponse, HttpWebResponse)
Dim responseStream As Stream = wresponse.GetResponseStream
Dim br As BinaryReader = New BinaryReader(responseStream)
Dim bytesize As Long = wresponse.ContentLength
Return br.ReadBytes(bytesize)
End Function
 
J

Joerg Jooss

Fred said:
Below is the code that I use to upload large files from my web server
virtual directory. This code locks up my application for quite a
while when a large file is moving. What modifications will allow
this code to execute in a asynchronous manner?

Function GetImageFromURL(ByVal url As String) As Byte()
Dim wr As HttpWebRequest =
DirectCast(WebRequest.Create(url),HttpWebRequest) If Not ProxyObject
Is Nothing Then wr.Proxy = ProxyObject
Dim wresponse As HttpWebResponse = DirectCast(wr.GetResponse,
HttpWebResponse) Dim responseStream As Stream =
wresponse.GetResponseStream
Dim br As BinaryReader = New BinaryReader(responseStream)
Dim bytesize As Long = wresponse.ContentLength
Return br.ReadBytes(bytesize)
End Function

Use asynchronous I/O: Instead of calling WebResponse.GetReponse(), use
BeginGetResponse() with EndGetResponse() to receive the response, and
BeginRead() with EndRead() to read from the response stream.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top