コード例 #1
0
        /// <summary>
        /// Makes a PATCH request to API
        /// </summary>
        /// <param name="endPoint">The api endPoint</param>
        /// <param name="stringBody">The request payload</param>
        /// <returns>The response</returns>
        public string patch(string endPoint, IPaymentRailsMappable body)
        {
            body.IsMappable();
            HttpContent jsonBody = convertBody(body.ToJson());
            string      result   = "";

            try
            {
                httpClient = createRequest(endPoint, "PATCH", body);

                var request = new HttpRequestMessage(new HttpMethod("PATCH"), endPoint)
                {
                    Content = jsonBody
                };
                System.Threading.Tasks.Task <HttpResponseMessage> responseTask = httpClient.SendAsync(request);

                HttpResponseMessage response = responseTask.Result;
                result = response.Content.ReadAsStringAsync().Result;
                if ((int)response.StatusCode != 200)
                {
                    throwStatusCodeException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
                }
            }
            catch (System.Net.Http.HttpRequestException)
            {
                throw new InvalidStatusCodeException(result);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Makes a POST request to API
        /// </summary>
        /// <param name="endPoint">The api endPoint</param>
        /// <param name="stringBody">The request payload</param>
        /// <returns>The Response</returns>
        public string post(string endPoint, IPaymentRailsMappable body)
        {
            body.IsMappable();
            HttpContent jsonBody = convertBody(body.ToJson());
            string      result   = "";

            try
            {
                httpClient = createRequest(endPoint, "POST", body);
                HttpResponseMessage response = httpClient.PostAsync(endPoint, jsonBody).Result;
                result = response.Content.ReadAsStringAsync().Result;
                if ((int)response.StatusCode != 200)
                {
                    throwStatusCodeException((int)response.StatusCode, response.Content.ReadAsStringAsync().Result);
                }
            }
            catch (System.Net.Http.HttpRequestException)
            {
                throw new InvalidStatusCodeException(result);
            }

            return(result);
        }