I am issuing a POST request through the HttpClient class and reading the response. It works about 90% of the time, but sometimes the response string is {}
and the endpoint I am hitting behaves as though it was issued a DELETE request with the same parameters as my POST request. This is my code
while (true)
{
HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string>());
string fliptUrl = _fliptUrl + flag;
var response = _http.PostAsync(fliptUrl, content).Result;
if (!response.IsSuccessStatusCode)
{
continue;
}
string responseString = response.Content.ReadAsStringAsync().Result;
Console.WriteLine(responseString);
if (responseString.Equals("404 page not found\n"))
{
throw new HttpRequestException("Flipt returned 404");
} else if (responseString.Equals("{}"))
{
continue;
}
Why would this be happening? Am I handling the asynchronous nature of the HttpClient in a weird way that is resulting in this behavior?
The print statement shown usually prints out {"key":"asdf","name":"asdf","description":"asdf","enabled":true,"createdAt":"2019-08-09T18:59:37.926184281Z","updatedAt":"2019-08-09T18:59:37.926184281Z"}
and in the edge case I am encountering it prints {}