Ejemplo n.º 1
0
        /// <summary>
        /// Creates the request object string out of a dictionary of parameters
        /// </summary>
        /// <param name="uri">The uri of the remote service</param>
        /// <param name="method">The Http verb for the request</param>
        /// <returns>An HttpWebRequest object</returns>
        private HttpWebRequest CreateHttpRequest(string uri, WebHeaderCollection headers, string httpMethod)
        {
            var request = WebRequest.CreateHttp(uri);

            request.Headers.Add(headers ?? new WebHeaderCollection());

            if (string.IsNullOrEmpty(request.Headers[HttpRequestHeader.Authorization]))
            {
                var parameters = new Dictionary <string, string>()
                {
                    { "oauth_token", Credentials.AccessToken.oauth_token },
                    { "oauth_token_secret", Credentials.AccessToken.oauth_token_secret }
                };

                string authHeaderValue = OAuthSvc.GetOAuthHeaderValue(new HttpMethod(httpMethod), uri, parameters);
                request.Headers[HttpRequestHeader.Authorization] = $"OAuth {authHeaderValue}";
            }

            //request.Headers[HttpRequestHeader.ContentType] = "application/xml";
            //request.Headers[HttpRequestHeader.Accept] = "application/xml";
            request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";

            request.Method = httpMethod;

            return(request);
        }