public void WhenUserClientPostTheReferenceCodeToTheWebsite()
        {
            APIContentType aPIContentType = APIContentType.Json;

            request  = "https://testapi.sit.sphereidentity.com/priceplans/getBusinessPricePlan";
            response = ApiHelper.InvokeApiPost(request, body, aPIContentType);
        }
Пример #2
0
        /// <summary>
        /// send the request for API with Post method and specific body content type. the API Content Type include XML,JSON, xwwwformurlencoded
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="body"></param>
        /// <param name="contenttype"></param>
        /// <returns>response </returns>
        public static string InvokeApiPost(string uri, string body, APIContentType contenttype)
        {
            HttpContent content = new StringContent(body, Encoding.UTF8);

            switch (contenttype)
            {
            case APIContentType.XML:
                content = new StringContent(body, Encoding.UTF8, "application/xml");
                break;

            case APIContentType.xwwwformurlencoded:
                content = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded");
                break;

            default:
                content = new StringContent(body, Encoding.UTF8, "application/json");
                break;
            }
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var res = ApiClient.PostAsync(uri, content).Result;

            _responseMessage = res;

            var response = JsonConvert.DeserializeObject <object>(_responseMessage.Content.ReadAsStringAsync().Result);

            ApiClient.DefaultRequestHeaders.Clear();
            return(response.ToString());
        }