public System.Net.HttpWebRequest makeHttpRequest(string method, string url, List<NameValuePairs> options)
{
System.Net.HttpWebRequest webRequest = null;
Dictionary<string, string> query = new Dictionary<string, string>();
try
{
if (options != null)
{
foreach (NameValuePairs np in options)
{
Object value = np.Value;
string key = np.Name;
query.Add(System.Web.HttpUtility.UrlEncode(key), System.Web.HttpUtility.UrlEncode(value.ToString()));
}
}
if ("POST".Equals(method.ToUpper().Trim()))
{
Uri newUrl = new System.Uri(url);
UriBuilder uriB = new UriBuilder(newUrl);
string queryString = string.Empty;
int counter = 0;
foreach (NameValuePairs np in options)
{
queryString += np.Name + "=" + np.Value;
if (counter < options.Count)
{
queryString += "&";
}
}
uriB.Query = queryString;
webRequest = System.Net.WebRequest.Create(uriB.Uri) as System.Net.HttpWebRequest;
webRequest.Method = "POST";
}
else if ("DELETE".Equals(method.ToUpper().Trim())){
Uri newUrl = new Uri(url);
UriBuilder uriB = new UriBuilder(newUrl);
string queryString = string.Empty;
int counter = 0;
foreach (NameValuePairs np in options)
{
queryString += np.Name + "=" + np.Value;
if (counter < options.Count)
{
queryString += "&";
}
}
uriB.Query = queryString;
webRequest = System.Net.WebRequest.Create(uriB.Uri) as System.Net.HttpWebRequest;
webRequest.Method = "DELETE";
}
else if ("PUT".Equals(method.ToUpper().Trim()))
{
Uri newUrl = new Uri(url);
UriBuilder uriB = new UriBuilder(newUrl);
string queryString = string.Empty;
int counter = 0;
foreach (NameValuePairs np in options)
{
queryString += np.Name + "=" + np.Value;
if (counter < options.Count)
{
queryString += "&";
}
}
uriB.Query = queryString;
webRequest = System.Net.WebRequest.Create(uriB.Uri) as System.Net.HttpWebRequest;
webRequest.Method = "PUT";
}
else
{
Uri newUrl = new Uri(url);
UriBuilder uriB = new UriBuilder(newUrl);
string queryString = string.Empty;
int counter = 0;
if (options != null)
{
foreach (NameValuePairs np in options)
{
queryString += np.Name + "=" + np.Value;
if (counter < options.Count)
{
queryString += "&";
}
}
}
uriB.Query = queryString;
webRequest = System.Net.WebRequest.Create(uriB.Uri) as System.Net.HttpWebRequest;
webRequest.Method = "GET";
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error in makeHttpRequest: " + ex.Message);
}
return webRequest;
}