Exemple #1
0
        public WebResponse MakeRequest()
        {
            var requestParams = CreateOAuthRequestParams();

            if (_sign)
            {
                var signature = OAuthSignature.Create(this, requestParams);
                requestParams.Add(OAuthParameters.OAuthSignature, signature);
            }

            string url;

            using (var sw = new StringWriter()) {
                sw.Write(RequestEndpoint.AbsoluteUri);
                sw.Write("?");

                var sorted = new SortedDictionary <string, string>();

                foreach (var p in Parameters)
                {
                    sorted.Add(p.Key, p.Value);
                }

                foreach (var p in requestParams)
                {
                    sorted.Add(p.Key, p.Value);
                }

                foreach (var p in sorted)
                {
                    sw.Write("{0}={1}", p.Key, p.Key == OAuthParameters.OAuthVerifier
                                                   ? HttpEncoder.UrlEncode(p.Value) : p.Value);

                    sw.Write("&");
                }
                // if params have been written the last item will be a '&' else it will be a '?'.
                sw.TrimEnd('&');
                sw.TrimEnd('?');

                url = sw.ToString();
            }

            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Accept = "*/*";
            request.Method = "GET";
            request.Headers.Add(HttpRequestHeader.Authorization, "OAuth");
            return(request.GetResponse());
        }
Exemple #2
0
        public string CreateXOAuthKey()
        {
            var requestParams = CreateOAuthRequestParams();

            if (_sign)
            {
                var signature = OAuthSignature.Create(this, requestParams);
                requestParams.Add(OAuthParameters.OAuthSignature, signature);
            }

            string token;

            using (var sw = new StringWriter()) {
                sw.Write("GET ");
                sw.Write(RequestEndpoint.AbsoluteUri);
                sw.Write(Characters.Space);

                var sorted = new SortedDictionary <string, string>();

                foreach (var p in Parameters)
                {
                    sorted.Add(p.Key, p.Value);
                }

                foreach (var p in requestParams)
                {
                    sorted.Add(p.Key, p.Value);
                }

                foreach (var p in sorted)
                {
                    sw.WriteFormat("{0}=\"{1}\",", p.Key, p.Value);
                }

                sw.TrimEnd(',');
                token = sw.ToString();
            }

            var bytes = Encoding.ASCII.GetBytes(token);

            return(Convert.ToBase64String(bytes));
        }