Exemple #1
0
        public string HttpPostBasicAuth(string endPoint, string query, string contentType = ContentTypeForm)
        {
            var data        = Encoding.UTF8.GetBytes(query);
            var headers     = new Dictionary <HttpRequestHeader, string>();
            var username    = this.Settings.ConsumerKey;
            var password    = this.Settings.ConsumerSecret;
            var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));

            headers.Add(HttpRequestHeader.Authorization, "Basic " + credentials);
            headers.Add(HttpRequestHeader.ContentType, contentType);
            return(OAuth2Consumer.HttpRequest(endPoint, "POST", data, headers));
        }
Exemple #2
0
        public string RestRequest(string endPoint, string verb, string accessToken, NameValueCollection nvc)
        {
            // var hvc = HttpUtility.ParseQueryString(string.Empty);
            // foreach (string key in nvc.Keys) hvc.Add(key, nvc[key]);
            // var data = Encoding.UTF8.GetBytes(hvc.ToString());
            // look at: http://stackoverflow.com/questions/829080/how-to-build-a-query-string-for-a-url-in-c
            // http://stackoverflow.com/questions/3865975/namevaluecollection-to-url-query

            var query = String.Join("&", nvc.AllKeys.Select(a => a + "=" + HttpUtility.UrlEncode(nvc[a])));
            var data  = Encoding.UTF8.GetBytes(query);

            var headers = new Dictionary <HttpRequestHeader, string>();

            headers.Add(HttpRequestHeader.Authorization, "Bearer " + accessToken);
            headers.Add(HttpRequestHeader.ContentType, ContentTypeForm);
            return(OAuth2Consumer.HttpRequest(endPoint, verb, data, headers));
        }