Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2012 HTTP Web Response Progress Bar

$
0
0
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

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


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>