I’m retrieving some data from Twitter using the code below
Dim FilterData = "follow=13,15"
Dim Request As WebRequest = HttpWebRequest.Create("https://stream.twitter.com/1/statuses/filter.json")
Request.ContentType = "application/x-www-form-urlencoded"
Request.Method = "POST"
Request.Credentials = New NetworkCredential("<Username>", "<Password>")
Request.ContentLength = FilterData.Length
Dim RequestStream = Request.GetRequestStream()
Dim RequestWriter As New StreamWriter(RequestStream)
RequestWriter.Write(FilterData)
RequestWriter.Close()
' Get the response.
Dim Response As WebResponse = Request.GetResponse()
Console.Writeline("Reached")
If I put a breakpoint on the Request.GetResponse() line, everything before it executes fine, however the following line is never hit – and nor is any exception handler. I don’t see any first chance exceptions in the output window.
This call is being made on a worker thread so the app continues to run but this worker doesn’t do anything else.
Can someone please point out the mistake?
You are trying to access a streaming API. Streaming APIs do not specify a Content-Length response header. They are continuously writing to the response. So you should use asynchronous API to access it. For example you could use a WebClient:
and the VB.NET equivalent: