HTTP persistent connection in C#

319 Views Asked by At

I have to make an HTTP persistent connection to a chinese security camera so I can obtain certain thermographic information. The manufacturer told me that they implemented HTTP persistent connection (I have never made persistent connections before).

This is the code I have right now:

        var uri = new Uri($"http://<cam's IPv4>/ISAPI/Thermal/channels/2/thermometry/realTimethermometry/rules?format=json");

        var credentialCache = new CredentialCache();
        credentialCache.Add(uri, "Digest", new NetworkCredential("test", "test"));

        using (var handler = new HttpClientHandler()
        {
            AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
            Credentials = credentialCache
        })
        {
            using (var httpClient = new HttpClient(handler))
            {
                httpClient.DefaultRequestHeaders.Add("Connection", "Keep-Alive");

                var response = await httpClient.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    return await response.Content.ReadAsStringAsync();
                }
                else
                {
                    return null;
                }
            }
        }

The thing is I'm not getting any response at all. How can I transform this code to HTTP 1.1 or make a persistent connection with this?.

For what I have been reading, there should only be an initial request and then I would keep receiving responses. Or at least that is what tbe manufacturer is telling me:

if you already called GET /ISAPI/Thermal/channels/2/thermometry/realTimethermometry/rules?format=json and established a connection, just receive alarms from the connection, please do not call GET /ISAPI/Thermal/channels/2/thermometry/realTimethermometry/rules?format=json again

0

There are 0 best solutions below