2
public TempOtpViewModel GetTempTop(TempOtpViewModel model)
{
        RestClient client = new RestClient(_appSettings.DalUrl);
        RestRequest request = new RestRequest("account/GetTempOtp", Method.POST);
        request.AddJsonBody(model);

        IRestResponse response = client.Execute(request);

        HttpStatusCode statusCode = response.StatusCode;
        int numericStatusCode = (int)statusCode;

        _logger.LogCritical("Serilog " + numericStatusCode);

        return null;
}

I am calling this API after I receive an OTP via SMS. It is returning status code 0 with an empty response.

However, if I wait for 2 seconds before calling it, it will work perfectly.

Any idea on what might be causing this issue?

Note that this issue is only happening in one environment. Our app is hosted in 2 environments is working properly in the other one.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • https://stackoverflow.com/questions/34795818/getting-a-httpstatuscode-of-0 – PlebFred Jul 09 '20 at 12:14
  • i checked the link that you shared. Actaully im not sure what is causing the error.I tried RestResponse instead of RestResponse but same thing. It works after 2 seconds –  Jul 09 '20 at 12:40

1 Answers1

0

If you are using RestSharp, Method.Get request make sure you don't set Header "Content-Type": "application/json". Because RestSharp complained about Method.Get request cannot have any content in its request. Also, try set ThrowOnAnyError = true to see a more detailed error if there is any.

// Init Rest Client
var options = new RestClientOptions("https://Local.com")
{
    MaxTimeout = -1,
    RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true,
    ThrowOnAnyError = true
};
var client = new RestClient(options);