.::ELITE::.
New member
- Joined
- Jul 13, 2006
- Messages
- 1
- Programming Experience
- Beginner
I am trying to download files in VB 2005 Asynchronously (To avoid UI JAM) , I need to HTTP POST the filename to the server and the file is being supplied as server response. Pls. guide. This is what I am currrently using but its OK only for Text, Html files. Tried code below but it corrupts binary files.


PHP:
Public Sub PostData(ByVal strURL As String, Optional ByVal POST1 As String = "")
' Declare a variable named client of type WebClient.
Dim myWebClient As WebClient
' Instantiate a WebClient object and assign it to the 'client' variable.
myWebClient = New WebClient
' Add handler to process theWebClient's DownloadProgressChanged events.
AddHandler myWebClient.UploadProgressChanged, AddressOf UploadProgress
' Add handler to process theWebClient's DownloadCompleted event.
AddHandler myWebClient.UploadStringCompleted, AddressOf UploadCompleted
' Declare a variable named downloadUri of type Uri
Dim downloadUri As Uri
' Instantiate a new Uri object and assign it to the 'downloadUri' variable.
downloadUri = New Uri(strURL)
myWebClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4")
'myWebClient.Headers.Add("Accept-Language", "en-us,en;q=0.5")
Try
myWebClient.UploadStringAsync(downloadUri, "filename=" &POST1)
End If
Catch e As System.Net.WebException
MsgBox("A web exception has occured [" & strURL & "]." & vbCrLf & " System returned: " & e.Message, MsgBoxStyle.Exclamation, "Error!")
Exit Try
Catch e As System.Net.ProtocolViolationException
MsgBox("A protocol violation has occured [" & strURL & "]." & vbCrLf & " System returned: " & e.Message, MsgBoxStyle.Exclamation, "Error!")
Exit Try
Catch e As System.Net.Sockets.SocketException
MsgBox("Socket error [" & strURL & "]." & vbCrLf & " System returned: " & e.Message, MsgBoxStyle.Exclamation, "Error!")
Exit Try
Catch e As System.IO.EndOfStreamException
MsgBox("An IO stream exception has occured. System returned: " & e.Message, MsgBoxStyle.Exclamation, "Error!")
Exit Try
End Try