RestSharp POST request keep staying in WaitingForActivation

Максим Егоров 1 Reputation point
2022-04-12T21:09:07.99+00:00

Here's my code which make an POST request

public static void PostInformation()
    {
        HttpRequests httpRequests = new(_apiUrl);

        Dictionary<string, string> @params = new() { };
        Dictionary<string, string> headers = new() { };

        var httpRequest = async () =>
        {
            await httpRequests.SendRequest(@params, headers, RestSharp.Method.Post);
        };
        var request = httpRequest();
    }

private static RestClient? _client;
private static RestRequest? _request;

public HttpRequests(string url)
{
    _client = new RestClient(url);
    _request = new RestRequest();
}

public async Task SendRequest(Dictionary<string, string> @params, 
                                             Dictionary<string, string> headers, Method method)
    {
        SetParams(@params);
        SetHeaders(headers);

        try
        { await _client?.ExecuteAsync(_request, method); }
        catch (Exception exception)
        { Console.WriteLine(exception.ToString()); }
        finally
        { _client?.Dispose(); }

        return null;
    }

And after running this code, the request status stops at WaitinigForActivation, so my question is, could this be because of the wrong JSON sent from the Dictionary named @params, or is there some other issue?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,535 questions
{count} votes