Response Event
Previous Top Next

The Response event is raised after a call to GetAsyncResponse and only after receiving the respond from the server.
You should check the value of ResponseCode before fetching the response stream to make sure that the response is valid.

Example:
Sub Globals
      total = 0
      URL = "http://www.basic4ppc.com/images/modules.jpg"
End Sub

Sub App_Start
      Form1.Show
      request.New1(URL)
      response.New1
      request.GetAsyncResponse
End Sub

Sub request_Response
      If request.ResponseCode = 200 Then '200 is the code of successful connections.
            response.Value = request.AsyncResponse
            total = Round(Response.ContentLength/1000)
            response.GetAsyncStream(AppPath & "\tempImage.jpg")
            timer1.Enabled = True
            btnCancel.Enabled = True
      Else
            Msgbox("Error getting response: " & request.ErrorMessage & CRLF _
            & "Response code: " & request.ResponseCode)
      End If
End Sub

Sub response_Stream
      Msgbox("Finished downloading file.")
      timer1.Enabled = False
End Sub

Sub Timer1_Tick
      label1.Text = "Download " & Round(response.DownloadedBytes / 1000) &" kb out of " & total & " kb"
End Sub

Sub btnCancel_Click
      response.CancelStream = True
      timer1.Enabled = False
End Sub