Skip to content

Instantly share code, notes, and snippets.

@davidglassborow
Forked from marekstachura/HttpClient.cs
Created January 18, 2019 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidglassborow/cc59afa45df6dd79160fb5aff706b0e4 to your computer and use it in GitHub Desktop.
Save davidglassborow/cc59afa45df6dd79160fb5aff706b0e4 to your computer and use it in GitHub Desktop.
C# http long polling example
var url = "http://localhost:8082/consumers/my_binary_consumer/instances/my_instance/topics/test";
using (var client = new HttpClient())
{
client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
var request = new HttpRequestMessage(HttpMethod.Get, url);
using (var response = await client.SendAsync(
request,
HttpCompletionOption.ResponseHeadersRead))
{
using (var body = await response.Content.ReadAsStreamAsync())
using (var reader = new StreamReader(body))
while (!reader.EndOfStream)
Console.WriteLine(reader.ReadLine());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment