Пример #1
0
        public T Put <T>(String url, Dictionary <string, string> headers, BaseRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Put,
                RequestUri = new Uri(url),
                Content    = JsonBuilder.ToJsonString(request)
            };

            foreach (var header in headers)
            {
                requestMessage.Headers.Add(header.Key, header.Value);
            }

            HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;

            return(JsonConvert.DeserializeObject <T>(httpResponseMessage.Content.ReadAsStringAsync().Result));
        }
Пример #2
0
        public T Delete <T>(String url, WebHeaderCollection headers, BaseRequest request)
        {
            HttpClient httpClient = new HttpClient();

            foreach (String key in headers.Keys)
            {
                httpClient.DefaultRequestHeaders.Add(key, headers.Get(key));
            }
            HttpRequestMessage requestMessage = new HttpRequestMessage
            {
                Content    = JsonBuilder.ToJsonString(request),
                Method     = HttpMethod.Delete,
                RequestUri = new Uri(url)
            };
            HttpResponseMessage httpResponseMessage = httpClient.SendAsync(requestMessage).Result;

            return(JsonConvert.DeserializeObject <T>(httpResponseMessage.Content.ReadAsStringAsync().Result));
        }
Пример #3
0
        // Async
        public async Task <T> PutAsync <T>(String url, Dictionary <string, string> headers, BaseRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Put,
                RequestUri = new Uri(url),
                Content    = JsonBuilder.ToJsonString(request)
            };

            foreach (var header in headers)
            {
                requestMessage.Headers.Add(header.Key, header.Value);
            }

            HttpResponseMessage httpResponseMessage = await HttpClient.SendAsync(requestMessage);

            return(await ReadResponseMessageAsync <T>(httpResponseMessage));
        }
Пример #4
0
        public T Put <T>(String url, WebHeaderCollection headers, BaseRequest request)
        {
            HttpClient httpClient = new HttpClient();

#if NETSTANDARD_1_6
            foreach (String key in headers.AllKeys)
            {
                httpClient.DefaultRequestHeaders.Add(key, headers[key]);
            }
#else
            foreach (String key in headers.Keys)
            {
                httpClient.DefaultRequestHeaders.Add(key, headers.Get(key));
            }
#endif
            HttpResponseMessage httpResponseMessage = httpClient.PutAsync(url, JsonBuilder.ToJsonString(request)).Result;
            return(JsonConvert.DeserializeObject <T>(httpResponseMessage.Content.ReadAsStringAsync().Result));
        }
        public T Delete <T>(String url, BaseRequest request, Options options)
        {
            HttpClient httpClient   = new HttpClient();
            string     randomString = DateTime.Now.ToString("ddMMyyyyhhmmssffff");

            httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
            httpClient.DefaultRequestHeaders.Add(RANDOM_HEADER_NAME, randomString);
            httpClient.DefaultRequestHeaders.Add(CLIENT_VERSION, "iyzipay-dotnet-2.1.9");
            httpClient.DefaultRequestHeaders.Add(AUTHORIZATION, PrepareAuthorizationString(request, randomString, options));
            HttpRequestMessage requestMessage = new HttpRequestMessage
            {
                Content    = JsonBuilder.ToJsonString(request),
                Method     = HttpMethod.Delete,
                RequestUri = new Uri(url)
            };
            HttpResponseMessage httpResponseMessage = httpClient.SendAsync(requestMessage).Result;

            return(JsonConvert.DeserializeObject <T>(httpResponseMessage.Content.ReadAsStringAsync().Result));
        }
Пример #6
0
        public T Delete <T>(String url, Dictionary <string, string> headers, BaseRequestV2 request) where T : IyzipayResourceV2
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage
            {
                Method     = HttpMethod.Delete,
                RequestUri = new Uri(url),
                Content    = JsonBuilder.ToJsonString(request)
            };

            foreach (var header in headers)
            {
                requestMessage.Headers.Add(header.Key, header.Value);
            }

            HttpResponseMessage httpResponseMessage = HttpClient.SendAsync(requestMessage).Result;
            var response = JsonConvert.DeserializeObject <T>(httpResponseMessage.Content.ReadAsStringAsync().Result);

            response.AppendWithHttpResponseHeaders(httpResponseMessage);
            return(response);
        }