public static async Task <string> CallApi(string accessToken)
        {
            var headers = new NameValueCollection();

            headers.Add("Authorization", Util.BuildAuthorizationHeader(accessToken));
            headers.Add("Accept", "application/json");

            var httpClientParameters = new HttpClientParameters
            {
                EndPoint     = Portal.ServiceURL,
                Method       = WebRequestMethods.Http.Post,
                Body         = Util.ReadJsonFromFile(),
                EncodingType = Encoding.UTF8,
                Headers      = headers,
                ContentType  = "application/json"
            };

            var httpClientHelper = new HttpClientHelper(httpClientParameters);

            await httpClientHelper.CallService();

            var result = httpClientHelper.Result;

            Console.WriteLine(result);
            httpClientHelper = null;
            return(result);
        }
        public static async Task <string> GetAccessToken()
        {
            var headers = new NameValueCollection();

            headers.Add("cache-control", "no-cache");

            var httpClientParameters = new HttpClientParameters
            {
                EndPoint     = string.Format(@"https://" + Portal.Domain + Portal.OAuth2URL),
                Body         = Util.CreateHttpRequestDataJSON(Util.BuildRequestParameters()),
                Method       = WebRequestMethods.Http.Post,
                EncodingType = Encoding.UTF8,
                Headers      = headers
            };

            var httpClientHelper = new HttpClientHelper(httpClientParameters);


            await httpClientHelper.CallService();

            Console.WriteLine(httpClientHelper.Result);

            var token = ((JObject)JsonConvert.DeserializeObject <dynamic>(httpClientHelper.Result))["access_token"]
                        .ToString();

            httpClientHelper = null;
            return(token);
        }
 public HttpClientHelper(HttpClientParameters httpClientParameters)
 {
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                            | SecurityProtocolType.Tls
                                            | SecurityProtocolType.Tls11
                                            | SecurityProtocolType.Tls12;
     HttpClientParameters = httpClientParameters;
 }