コード例 #1
0
 protected async Task Get(
     string url, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> response = null)
 {
     await MakeRequest(HttpMethod.Get, url, null, headers, response);
 }
コード例 #2
0
 protected async Task Put(string url, object data = null, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> outResponse = null)
 {
     await MakeRequest(HttpMethod.Put, url, data, headers, outResponse);
 }
コード例 #3
0
        protected async Task <T> Put <T>(string url, object data = null, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> outResponse = null)
        {
            var result = await MakeRequest(HttpMethod.Put, url, data, headers, outResponse);

            return(await DeserializeOrDefault <T>(result));
        }
コード例 #4
0
        private async Task <HttpResponseMessage> MakeRequest(
            HttpMethod method, string url, object data = null, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> outResponse = null)
        {
            var message = GetMessage(method, url, headers);
            HttpResponseMessage result;

            using (message.Content = GetMessageContent(data))
            {
                using (var client = GetClient())
                {
//                     Console.WriteLine("DEBUG MODE: Request\n"
//                              + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
//                              + method + ": " + url + "\n"
//                              + "Headers: " + headers + "\n"
//                              + "Payout: " + json + "\n");

                    result = await client.SendAsync(message);

//                    Console.WriteLine("DEBUG MODE: Response\n"
//                                      + "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"
//                                      + "Code: " + result.StatusCode + "\n"
//                                      + "Headers: " + Serialize(result.Headers) + "\n"
//                                      + "Body: " + await result.Content.ReadAsStringAsync() + "\n");

                    await ThrowIfError(result);
                }
            }

            if (outResponse != null)
            {
                outResponse.Value = result;
            }
            return(result);
        }
コード例 #5
0
 protected Task Delete(string url, object data = null, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> outResponse = null)
 {
     return(MakeRequest(HttpMethod.Delete, url, data, headers, outResponse));
 }
コード例 #6
0
 protected Task Patch(string url, object data = null, IDictionary <string, string> headers = null, Ref <HttpResponseMessage> outResponse = null)
 {
     return(MakeRequest(new HttpMethod("PATCH"), url, data, headers, outResponse));
 }