Skip to content

Instantly share code, notes, and snippets.

@marekstachura
Last active December 30, 2022 18:28
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save marekstachura/2941d7dbd80f82c92af9 to your computer and use it in GitHub Desktop.
Save marekstachura/2941d7dbd80f82c92af9 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());
}
}
@ahvahsky2008
Copy link

But its work once.

@Kanat9494
Copy link

Kanat9494 commented Nov 26, 2022

Yeah, it works only once

@dmitrydvm
Copy link

To make this code run indefinitely just put part of it in an infinite loop
while (true) { //code starting line 8 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment