Last active
December 30, 2022 18:28
-
-
Save marekstachura/2941d7dbd80f82c92af9 to your computer and use it in GitHub Desktop.
C# http long polling example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
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
Yeah, it works only once