예제 #1
0
        async Task <TResult> SendRequest <TRequest, TResult>(HttpMethod httpMethod, string additionalUrlPath, TRequest data, string endpointURL, WowzaQueryParams queryParams = null)
        {
            HttpResponseMessage response;

            using (var request = new HttpRequestMessage(httpMethod, $"{endpointURL}{additionalUrlPath}"))
            {
                request.BuildQueryParams(queryParams);
                request.AddWowzaRequestHeaders(Wowza.Apikey, $"{ApiSignaturePath}{EndPoint}{additionalUrlPath}", Wowza.UseBasicAuth);

                if (httpMethod != HttpMethod.Get && data != null)
                {
                    var jsonSerializer = new JsonSerializerSettings {
                        NullValueHandling = NullValueHandling.Ignore
                    };
                    request.Content = new StringContent(JsonConvert.SerializeObject(data, Formatting.Indented, jsonSerializer), Encoding.UTF8, "application/json");
                }
                response = await httpClient.SendAsync(request);
            }
            if (response != null && response.IsSuccessStatusCode)
            {
                var jsonContent = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(jsonContent))
                {
                    try
                    {
                        TResult result = await Task.Run(() => JsonConvert.DeserializeObject <TResult>(jsonContent));

                        return(result);
                    }
                    catch (Exception ex)
                    {
                        throw new WowzaException(ex.Message, ex.InnerException);
                    }
                }
                else
                {
                    return(default);