public override System.Net.WebResponse ExecuteFeed(string feedURL, IProvider provider, BusinessObjects.Token connectionToken, BusinessObjects.TRANSPORT_METHOD transportMethod) { string signature = ""; OAuthHelper oauthHelper = new OAuthHelper(); QueryParameters oauthParams = new QueryParameters(); oauthParams.Add("oauth_consumer_key", provider.Consumerkey); oauthParams.Add("oauth_nonce", oauthHelper.GenerateNonce()); oauthParams.Add("oauth_signature_method", provider.SignatureMethod.ToString()); oauthParams.Add("oauth_timestamp", oauthHelper.GenerateTimeStamp()); oauthParams.Add("oauth_token", connectionToken.AccessToken); oauthParams.Add("oauth_version", "1.0"); ////1. Generate Signature signature = oauthHelper.GenerateSignature(new Uri(feedURL), oauthParams, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, TRANSPORT_METHOD.GET, connectionToken.TokenSecret); oauthParams.Add("oauth_signature", signature); //3.Connect and Execute Feed HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(feedURL); request.Method = transportMethod.ToString(); request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParams)); //request.ContentType = "application/atom+xml"; request.ContentLength = 0; WebResponse wr; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString() + Environment.NewLine + "Request Parameters: " + oauthParams.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); } return(wr); }
public override System.Net.WebResponse ExecuteFeed(string feedURL, IProvider provider, BusinessObjects.Token connectionToken, BusinessObjects.TRANSPORT_METHOD transportMethod, byte[] content = null, Dictionary <string, string> headers = null) { string signature = ""; OAuthHelper oauthHelper = new OAuthHelper(); string timestamp = oauthHelper.GenerateTimeStamp(); QueryParameters oauthParams = new QueryParameters(); oauthParams.Add("oauth_consumer_key", provider.Consumerkey); oauthParams.Add("oauth_nonce", oauthHelper.GenerateNonce()); oauthParams.Add("oauth_signature_method", provider.SignatureMethod.ToString()); oauthParams.Add("oauth_timestamp", timestamp); oauthParams.Add("oauth_token", connectionToken.AccessToken); oauthParams.Add("oauth_version", "1.0"); signature = oauthHelper.GenerateSignature(new Uri(feedURL), oauthParams, provider.Consumerkey, provider.Consumersecret, provider.SignatureMethod, TRANSPORT_METHOD.POST, connectionToken.TokenSecret); oauthParams.Add("oauth_signature", signature); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(feedURL); request.Method = transportMethod.ToString(); if (headers != null) { foreach (var header in headers) { switch (header.Key) { case "ContentLength": { request.ContentLength = long.Parse(header.Value); break; } case "ContentType": { request.ContentType = header.Value; break; } default: { request.Headers[header.Key] = header.Value; break; } } } } request.ContentLength = (content == null) ? 0 : content.Length; request.Headers.Add("Authorization", oauthHelper.GetAuthorizationHeader(oauthParams)); request.GetRequestStream().Write(content, 0, content.Length); WebResponse wr = null; try { logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString() + Environment.NewLine + "Request Parameters: " + oauthParams.ToString()); wr = (WebResponse)request.GetResponse(); logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString()); } catch (Exception ex) { logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, oauthParams), ex); } return(wr); }