Home > Software design >  monitoring POST requests from HttpClients c#
monitoring POST requests from HttpClients c#

Time:12-17

I have created a WEB API that receives POSTs from HttpClients as JSON messages(ID,Name). My target is to check if my remote computers are alive, so the Httpclient sends a POST message every 24 hours to the server. So far I have managed to save all the messages from the remote clients to a text file.

So, my question is, what is the best way to track all the messages and know which client didn't post for the last 48 hours?

Thank you,

Shay.

CodePudding user response:

I use PostAsJsonAsync method to send json
"X-Version: 1"
This is what I have done so far

using (var client = new HttpClient()) {
    client.BaseAddress = new Uri("https://api.clickatell.com/");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "xxxxxxxxxxxxxxxxxxxx");
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    var response = client.PostAsJsonAsync("rest/message", svm).Result;
}

CodePudding user response:

Well, jou need to cron a task that does just the contrary you do when you received the post from the remote computer.

Open the file, read it and check against the list of computers (that I suppose you have in ANOTHER text file)

so use a stream reader, and parse the content of each line you read...

After this is done rename the file :P

  • Related