Hi everyone,
I am trying to build a Progress Bar for a Web Request/Response. Sometimes the response can take up to a minute and I would like a progress bar to show a status. The problem I am facing, is that I am receiving a content length for the response of a -1. Honestly, once I get the content Length I do not even know where to begin. I am new to Visual Basic. Any help would be greatly appreciated
I am trying to build a Progress Bar for a Web Request/Response. Sometimes the response can take up to a minute and I would like a progress bar to show a status. The problem I am facing, is that I am receiving a content length for the response of a -1. Honestly, once I get the content Length I do not even know where to begin. I am new to Visual Basic. Any help would be greatly appreciated
Code:
Dim responseString As String = Nothing
Dim responseArray As Byte() = Nothing
Dim apiRequest As WebRequest = WebRequest.Create(URL)
apiRequest.ContentType = "application/x-www-form-urlencoded"
apiRequest.Method = "POST"
apiRequest.Timeout = 5000
apiRequest.ContentLength = 0
Using apiWebResponse As WebResponse = apiRequest.GetResponse()
Using stream As Stream = apiWebResponse.GetResponseStream()
Console.WriteLine(apiWebResponse.ContentLength)
Using ms = New MemoryStream()
stream.CopyTo(ms)
responseArray = ms.ToArray()
responseString = String.Join("", responseArray)
End Using
End Using
End Using