Exemplo n.º 1
0
        public string CallApi()
        {
            //ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

            using (var client = new HttpClient())
            {
                if (!string.IsNullOrWhiteSpace(access_token))
                {
                    // Conver Token Object(json) to Class [{"access_token":"xxx", "token_type":"yyy", "expires_in":zzz}]
                    //var t = JsonConvert.DeserializeObject<Token>(token);

                    client.DefaultRequestHeaders.Clear();
                    client.DefaultRequestHeaders.Add("Authorization", token_type + " " + access_token);
                }
                var response = client.GetAsync(url).Result;
                return(JsonProvider.FormatJson(response.Content.ReadAsStringAsync().Result));
            }
        }
Exemplo n.º 2
0
        public string GetTokenFormat()
        {
            var pairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "password"),
                new KeyValuePair <string, string>("username", userName),
                new KeyValuePair <string, string> ("Password", password)
            };
            var content = new FormUrlEncodedContent(pairs);

            //System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            //System.Net.ServicePointManager.ServerCertificateValidationCallback =
            //    new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; });

            using (var client = new HttpClient())
            {
                var response = client.PostAsync(url, content).Result;
                return(JsonProvider.FormatJson(response.Content.ReadAsStringAsync().Result));
            }
        }