private string GetSignature(Rest.HttpMethod httpMethod, string path, string contentMd5, string date, string contentType) { string canonicalString = string.Format("{0},{1},{2},{3},{4}", httpMethod.ToString(), contentType, contentMd5, _apiVersion + path, date); return(MifielUtils.CalculateHMAC(AppSecret, canonicalString)); }
private HttpContent SendRequest(Rest.HttpMethod httpMethod, string path, HttpContent content) { string requestUri = url + _apiVersion + path; HttpRequestMessage requestMessage = null; HttpResponseMessage httpResponse = null; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromMinutes(5); using (content) { switch (httpMethod) { case Rest.HttpMethod.POST: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, requestUri); requestMessage.Content = content; break; case Rest.HttpMethod.GET: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Get, requestUri); break; case Rest.HttpMethod.PUT: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Put, requestUri); requestMessage.Content = content; break; case Rest.HttpMethod.DELETE: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Delete, requestUri); break; default: throw new MifielException("Unsupported HttpMethod: " + httpMethod.ToString()); } SetAuthentication(httpMethod, path, requestMessage); httpResponse = client.SendAsync(requestMessage).Result; if (!httpResponse.IsSuccessStatusCode) { throw new MifielException("Status code error: " + httpResponse.StatusCode, httpResponse.Content.ReadAsStringAsync().Result); } return(httpResponse.Content); } } }
private HttpContent SendRequest(Rest.HttpMethod httpMethod, string path, HttpContent content) { string requestUri = url + _apiVersion + path; //string requestUri = "https://requestb.in/1cuddmz1"; HttpRequestMessage requestMessage = null; HttpResponseMessage httpResponse = null; using (var client = new HttpClient()) { using (content) { switch (httpMethod) { case Rest.HttpMethod.POST: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Post, requestUri); requestMessage.Content = content; break; case Rest.HttpMethod.GET: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Get, requestUri); break; case Rest.HttpMethod.PUT: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Put, requestUri); requestMessage.Content = content; break; case Rest.HttpMethod.DELETE: requestMessage = new HttpRequestMessage(System.Net.Http.HttpMethod.Delete, requestUri); break; default: throw new MifielException("Unsupported HttpMethod: " + httpMethod.ToString()); } SetAuthentication(httpMethod, path, requestMessage); httpResponse = client.SendAsync(requestMessage).Result; if (!httpResponse.IsSuccessStatusCode) { throw new MifielException("Status code error: " + httpResponse.StatusCode, httpResponse.Content.ReadAsStringAsync().Result); } return(httpResponse.Content); } } }