public string SendRequest() /*This public interface receives the request and send the response of type string. */ { string FinalResponse = ""; string Cookie = ""; NameValueCollection collHeader = new NameValueCollection(); HttpWebResponse webresponse; HttpBaseClass BaseHttp = new HttpBaseClass(UserName, UserPwd, ProxyServer, ProxyPort, Request); try { HttpWebRequest webrequest = BaseHttp.CreateWebRequest(URI, collHeader, RequestMethod, true); webresponse = (HttpWebResponse)webrequest.GetResponse(); string ReUri = BaseHttp.GetRedirectURL(webresponse, ref Cookie); //Check if there is any redirected URI. webresponse.Close(); ReUri = ReUri.Trim(); if (ReUri.Length == 0) //No redirection URI { ReUri = URI; } RequestMethod = "POST"; FinalResponse = BaseHttp.GetFinalResponse(ReUri, Cookie, RequestMethod, true); }//End of Try Block catch (WebException e) { throw CatchHttpExceptions(FinalResponse = e.Message); } catch (System.Exception e) { throw new Exception(FinalResponse = e.Message); } finally { BaseHttp = null; } return FinalResponse; } //End of SendRequestTo method
public void SendTwitterDirectMessage_old(List<string> twitterUserList, string message) { // APP Constants // Generating timestamp and 64 Biuts key. var nounce_value = Generator.Generate64BitsKey(); var oauth_timestamp = Generator.GenerateTimeStamp(); // Creating and setting the Authenticatin object var twitterAuthenticator = new TwitterAPIAuthentication(urlTweeterAPICall); twitterAuthenticator.AddAuthParameter("include_entities", "true"); twitterAuthenticator.AddAuthParameter("oauth_consumer_key", app_consumer_key); twitterAuthenticator.AddAuthParameter("oauth_nonce", nounce_value); twitterAuthenticator.AddAuthParameter("oauth_signature_method", app_signature_method); twitterAuthenticator.AddAuthParameter("oauth_timestamp", oauth_timestamp); twitterAuthenticator.AddAuthParameter("oauth_token", app_token); twitterAuthenticator.AddAuthParameter("oauth_version", app_oauth_version); // Now, setting the content of message var twitterUserListUnify = new StringBuilder(); foreach (string userName in twitterUserList) twitterUserListUnify.Append(userName); twitterAuthenticator.AddAuthParameter("screen_name", twitterUserListUnify.ToString()); twitterAuthenticator.AddAuthParameter("text", message); // Generating the signature method twitterAuthenticator.GenerateSignatureParameter("POST", app_consumerSecret, app_TokenSecret); // Process the request header var authParameters = twitterAuthenticator.GetAllParameters(); var authParameters_ToHeader = new StringBuilder(); string [] parameterContent; authParameters_ToHeader.Append("OAuth "); for (int cont = 0; cont < authParameters.Count; cont++){ parameterContent = authParameters[cont].Split("§".ToCharArray()); // Encode the parameters to Percent Format parameterContent[0] = Uri.EscapeDataString(parameterContent[0]); parameterContent[1] = Uri.EscapeDataString(parameterContent[1]); authParameters_ToHeader.Append(parameterContent[0]); authParameters_ToHeader.Append("=" + '"'); authParameters_ToHeader.Append(parameterContent[1]); authParameters_ToHeader.Append('"'); if(cont < authParameters.Count-1) authParameters_ToHeader.Append(", "); } NameValueCollection headerContent = new NameValueCollection(); //headerContent.Add("Authorization", authParameters_ToHeader.ToString().Replace("\\","")); headerContent.Add("Authorization", "OAuth oauth_consumer_key=\"UElYlAUyfo7S2aNf0aBnsA60c\", oauth_nonce=\"cb9a3d3cebb2ab473af86240075b14b8\", oauth_signature=\"Cjn4plMGgH3BvScOgNCLP6sP4H4%3D\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1451156047\", oauth_token=\"72423411-T1vi02fZmxzIfEi0RIVwYWbNMwq9fdxzsKHdVQKXB\", oauth_version=\"1.0\""); // Now, start the WebRequest var webRequestProcessor = new HttpBaseClass("", "", "", 0, ""); var httpRequest = webRequestProcessor.CreateWebRequest(urlTweeterAPICall, headerContent, "POST", true); var response = httpRequest.GetResponse(); }