Exemple #1
0
        protected async Task <object> SendMessageAsync(string url, object model, Type typeOfResponse,
                                                       IEnumerable <HttpHeader> headers = null, DataFormat dataFormat                = DataFormat.Json, ISerializer jsonSerializer = null,
                                                       bool includeCertificate          = false, CancellationToken cancellationToken = default)
        {
            RestClient = await GetRestClientAsync(includeCertificate);

            var restRequest = await PrepareRequestAsync(url, model, Method.POST, headers, dataFormat, jsonSerializer, includeCertificate);

            Logger.LogInformation($"{CurrentActor} is going to dispatch http request {jsonSerializer.Serialize(model)}");
            var response = await RestClient.ExecuteTaskAsync(restRequest, cancellationToken);

            // ensure success response
            RestClient.EnsureResponseWasSuccessful(restRequest, response);

            Logger.LogInformation($"{CurrentActor} response from dispatch successfully with status code {response.StatusCode}, {response.StatusDescription} : {response.Content}");
            var result = HandleResponse(response, typeOfResponse);

            return(result);
        }