/// <summary> /// Generate a HttpWebResponse to enable Twitter connection /// </summary> /// <param name="method_uri"> /// The Uri represents the Url to be requested on Twitter API /// </param> /// <returns>Return a web_request to be used thanks to a webresponse and query twitter</returns> public HttpWebRequest GenerateRequest(Uri method_uri) { _generateDelegate = new GenerateConnectionDelegate(generateHeaders); #region Initializing query parameters _queryParameters = new SortedDictionary <string, string>(); if (!string.IsNullOrEmpty(method_uri.Query)) { foreach (Match variable in Regex.Matches(method_uri.Query, @"(?<varName>[^&?=]+)=(?<value>[^&?=]+)")) { _queryParameters.Add(variable.Groups["varName"].Value, variable.Groups["value"].Value); } } #endregion #region Creating the webRequest string query = method_uri.ToString(); string headersParameters = generateParameters(method_uri); try { HttpWebRequest webRequest = WebRequest.Create(method_uri.ToString()) as HttpWebRequest; webRequest.Method = this._method.ToString(); webRequest.Headers.Add("Authorization", headersParameters); webRequest.ServicePoint.Expect100Continue = false; return(webRequest); } catch (WebException) { return(null); } catch (Exception ex) { throw ex; } #endregion }
/// <summary> /// Generate a HttpWebResponse to enable Twitter connection /// </summary> /// <param name="method_uri"> /// The Uri represents the Url to be requested on Twitter API /// </param> /// <returns>Return a web_request to be used thanks to a webresponse and query twitter</returns> public HttpWebRequest GenerateRequest(Uri method_uri) { _generateDelegate = new GenerateConnectionDelegate(generateHeaders); #region Initializing query parameters _queryParameters = new SortedDictionary<string, string>(); if (!string.IsNullOrEmpty(method_uri.Query)) { foreach (Match variable in Regex.Matches(method_uri.Query, @"(?<varName>[^&?=]+)=(?<value>[^&?=]+)")) _queryParameters.Add(variable.Groups["varName"].Value, variable.Groups["value"].Value); } #endregion #region Creating the webRequest string query = method_uri.ToString(); string headersParameters = generateParameters(method_uri); try { HttpWebRequest webRequest = WebRequest.Create(method_uri.ToString()) as HttpWebRequest; webRequest.Method = this._method.ToString(); webRequest.Headers.Add("Authorization", headersParameters); webRequest.ServicePoint.Expect100Continue = false; return webRequest; } catch (WebException) { return null; } catch (Exception ex) { throw ex; } #endregion }