I am using Httpclient C # .net to connect to a url.
I need to make a GET request. This connection is persistent. The problem is that I need to perform actions according to the notifications that the server sends me.
When executing the HttpResponseMessage
, it hangs (being persistent it works and receiving notifications constantly, but it never gives me back control to be able to work according to the notifications of the server)
when canceling the execution I can see all notifications by console.
Is there any way to control HttpResponseMessage
to be able to work with every response the server sends me?
Should I use another type of technology for this?
This is what I get back by console de "await response.Content.ReadAsStringAsync ();"
when I cancel the operation.
<? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<message xmlns = "http://asdasd.com/asd/08/DS/Sync" xmlns: ns2 = "http: // asdadasdasdasd">
<event> KEEPALIVE </ event>
</ message>
<? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<message xmlns = "http://asdasd.com/asd/08/DS/Sync" xmlns: ns2 = "http: // asdadasdasdasd">
<event> KEEPALIVE </ event>
</ message>
<? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>
<message xmlns = "http://asdasd.com/asd/08/DS/Sync" xmlns: ns2 = "http: // asdadasdasdasd">
<event> KEEPALIVE </ event>
</ message>
every ('message') arrives approximately every 2 minutes I wish that each time I get one I can perform an action I leave the code that ultilizo. Thank you
public async static Task<int> GetRequest(string url)
{
HttpClient client = new HttpClient();
HttpResponseMessage response = new HttpResponseMessage();
response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
Console.WriteLine("STATUS OF CONNECTION");
Console.WriteLine(response.StatusCode);
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false); ;
Console.WriteLine("ANSWER");
Console.WriteLine(body);
Console.WriteLine(" \n");
Console.WriteLine("\n ATTENTION!! Disconnected from the Persistence line \n");
Console.WriteLine("Connections done");
int result1 = 1;
return result1;
}