Пример #1
0
        protected override async Task Execute(WorkflowInstance instance)
        {
            using (var client = new HttpClient())
            {
                var url = RequestParameters != null && RequestMethod == HttpMethod.Get
                    ? RequestUrl.ToUrl(RequestParameters.ToArray())
                    : RequestUrl.ToUrl();

                var request = new HttpRequestMessage(RequestMethod, url);

                if (RequestMethod == HttpMethod.Post)
                {
                    if (JsonData != null)
                    {
                        request.Content = JsonData.AsJsonContent();
                    }
                    else if (RequestParameters != null)
                    {
                        request.Content =
                            new FormUrlEncodedContent(
                                RequestParameters.ToDictionary(
                                    k => k.Key,
                                    v => v.Value?.ToString() ?? string.Empty));
                    }
                }

                var response = await client.SendAsync(request);

                ResponseAction?.Invoke(response);
            }
        }