Creating an Http Get & Post Request at Runtime to process Web pages and transfer files
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Collections;
using
System.Net;
using
System.IO;
using
System.Text.RegularExpressions;
using
System.Web;
using
Microsoft.Win32;
using
System.Security.Permissions;
namespace
AlladinHttpRequestResponse
{
/// <summary>
/// Description: This class creates Http Get & Http Post request for uploading, downloading text and binary data of form fields & file to any web server on any platform with HTTP standards i.e. post or get form method with any kind of application windows forms, console app or web forms.
/// Few Features Supported By This Class on any web server on any platform:
/// 1) Downloads raw HTML or XML data from.
/// 2) Saves the Downloaded HTML/XML/Binary data to the local file system e.g. c:\download.
/// 3) Creates dynamic post form method header which can post form data thus enabling one to process Request.Form method on the calling web page e.g. default.asp.
/// 4) Creates dynamic HTTP post form method header which can upload files i.e. (text/binary) along with form data from the local machine to the any web server on any platform with HTTP standards.
/// 5) Creates & retrives dynamic HTTP headers which can enable one to process Request.Header method on the calling web page e.g. default.asp.
/// 6) Creates & retrives dynamic HTTP cookies which can enable one to process Request.Cookies method on the calling web page e.g. default.asp.
///7) Retrives Http Status Code after sending the http request.
///8) Retrives Http Status Description after sending the http request.
///9) Retrives Http Character Set after sending the http request.
///10) Retrives Http Content Encoding after sending the http request.
///11) Retrives Http Content Last Modified after sending the http request.
///12) Retrives Http Content Length after sending the http request.
///13) Retrives Http Content Type after sending the http request.
///14) Retrives Http Method after sending the http request.
///15) Retrives Http ProtocolVersion after sending the http request.
///16) Retrives Http Server Name after sending the http request.
/// </summary>
public class HTTPResponseRequest
{
#region
Const Declaration
/// <summary>
/// Sets The Get String.
/// </summary>
private const string GET = "GET";
/// <summary>
/// Sets The Post String.
/// </summary>
private const string POST = "POST";
/// <summary>
/// FileUpload String.
/// </summary>
private const string FILEUPLOAD = "FileUpload";
/// <summary>
/// Forwardslash String.
/// </summary>
private const char FORWARDSLASH = '/';
/// <summary>
/// Sets The BackSlash String.
/// </summary>
private const char BACKSLASH = '\\';
/// <summary>
/// Sets The Default Buffer Size.
/// </summary>
private const int BUFFERSIZE = 1024;
/// <summary>
/// Sets Zero Integer.
/// </summary>
private const int INT_ZERO = 0;
/// <summary>
/// Sets One Integer.
/// </summary>
private const int INT_ONE = 1;
/// <summary>
/// Sets ContentType String For Get & Post Methods.
/// </summary>
private const string CONTENTTYPE = "application/x-www-form-urlencoded";
/// <summary>
/// Sets contentType String For HTTP FileUpload.
/// </summary>
private const string FILEUPLOADCONTENTTYPE = "multipart/form-data";
/// <summary>
/// Amperstant String.
/// </summary>
private const string AMPERSTANT = "&";
/// <summary>
/// Equalto String.
/// </summary>
private const string EQUALTO = "=";
/// <summary>
/// MultipleDash String.
/// </summary>
private const string MULTIPLEDASH = "-----------------------------";
/// <summary>
/// boundary String.
/// </summary>
private const string BOUNDARY = "boundary";
/// <summary>
/// Colan String.
/// </summary>
private const string COLAN = ";";
/// <summary>
/// FileUploadlinebreak Charactor String.
/// </summary>
private const string FILEUPLOADLINEBREAKCHAR = "\r\n";
#endregion
#region
Member Variable Declaration
/// <summary>
/// Sets The Http Form Method String.
/// </summary>
private string strRequestMethod;
/// <summary>
/// Sets The WebRequest Object.
/// </summary>
private HttpWebRequest request;
/// <summary>
/// Sets The WebResponse Object.
/// </summary>
private HttpWebResponse response;
/// <summary>
/// Sets The Http Url String.
/// </summary>
private string strURL;
/// <summary>
/// Sets The Httpresponse Stream Object.
/// </summary>
private Stream responseStream;
/// <summary>
/// Sets The WebProxy Url String.
/// </summary>
private string strWebProxyUrl;
/// <summary>
/// Sets Web Request contentType.
/// </summary>
private string strRequestContentType = CONTENTTYPE;
/// <summary>
/// Sets Web Request Post Form Method String.
/// </summary>
private string strPostData = "";
/// <summary>
/// Sets Web Request File Uploads Boundary String.
/// </summary>
private string strFileUploadboundary = MULTIPLEDASH + DateTime.Now.Ticks.ToString("x");
/// <summary>
/// Sets The Hashtable for Post Data or File Upload Data.
/// </summary>
private Hashtable hashtablePostData;
/// <summary>
/// Sets The Web Response Content Length.
/// </summary>
private long longResponseContentLength = INT_ZERO;
/// <summary>
/// Sets The Web Response Content Type.
/// </summary>
private string strResponseContentType = "";
/// <summary>
/// Sets The Web Response URL.
/// </summary>
private string strResponseURL = "";
/// <summary>
/// Sets The Web Response Headers.
/// </summary>
private Hashtable hashtableWebResponseHeader = new Hashtable();
/// <summary>
/// Sets The Web Request Headers.
/// </summary>
private Hashtable hashtableWebRequestHeader;
/// <summary>
/// Sets The Web Response Cookie Collection.
/// </summary>
private CookieCollection cookiecolWebResponseCookies = new CookieCollection();
/// <summary>
/// Sets The Web Request Cookie Collection.
/// </summary>
private CookieCollection cookiecolWebRequestCookies;
/// <summary>
/// Sets The Web Response Content Encoding.
/// </summary>
private string strWebResponseContentEncoding = "";
/// <summary>
/// Sets The Web Response CharacterSet.
/// </summary>
private string strWebResponseCharacterSet = "";
/// <summary>
/// Sets The Web Response Status Description.
/// </summary>
private string strWebResponseStatusDescription = "";
/// <summary>
/// Sets The Web Response Method.
/// </summary>
private string strWebResponseMethod = "";
/// <summary>
/// Sets The Web Response Content Last Modified.
/// </summary>
private DateTime datetimeWebResponseContentLastModified = new DateTime();
/// <summary>
/// Sets The Web Response Protocol Version.
/// </summary>
private string strWebResponseProtocolVersion = "";
/// <summary>
/// Sets The Web Response Server.
/// </summary>
private string strWebResponseServer = "";
/// <summary>
/// Sets The Web Response Status Code.
/// </summary>
private string strWebResponseStatusCode = "";
//
private bool blnFileCopyLocationIncludesName;
#endregion
#region
Property Declaration
/// <summary>
/// This Property Is Used To Set WebProxyUrl Incase There is a Proxy Server.
/// </summary>
public string WebProxyUrl
{
set
{
this.strWebProxyUrl = value;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Content Length.
/// </summary>
public long WebResponseContentLength
{
get
{
return this.longResponseContentLength;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Content Type.
/// </summary>
public string WebResponseContentType
{
get
{
return this.strResponseContentType;
}
}
/// <summary>
/// This Property Is Used To Get Web Response URL.
/// </summary>
public string ResponseURL
{
get
{
return this.strResponseURL;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Header.
/// </summary>
public Hashtable WebResponseHeader
{
get
{
return this.hashtableWebResponseHeader;
}
}
/// <summary>
/// This Property Is Used To Set Web Request Header.
/// </summary>
public Hashtable WebRequestHeader
{
set
{
this.hashtableWebRequestHeader = value;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Cookie Collection.
/// </summary>
public CookieCollection WebResponseCookies
{
get
{
return this.cookiecolWebResponseCookies;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Cookie Collection.
/// </summary>
public CookieCollection WebRequestCookies
{
set
{
this.cookiecolWebRequestCookies = value;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Content Encoding.
/// </summary>
public string WebResponseContentEncoding
{
get
{
return this.strWebResponseContentEncoding;
}
}
/// <summary>
/// This Property Is Used To Get Web Response CharacterSet.
/// </summary>
public string WebResponseCharacterSet
{
get
{
return this.strWebResponseCharacterSet;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Status Description.
/// </summary>
public string WebResponseStatusDescription
{
get
{
return this.strWebResponseStatusDescription;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Method.
/// </summary>
public string WebResponseMethod
{
get
{
return this.strWebResponseMethod;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Content Last Modified.
/// </summary>
public DateTime WebResponseContentLastModified
{
get
{
return this.datetimeWebResponseContentLastModified;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Protocol Version.
/// </summary>
public string WebResponseProtocolVersion
{
get
{
return this.strWebResponseProtocolVersion;
}
}
/// <summary>
/// This Property Is Used To Get Web Response Server.
/// </summary>
public string WebResponseServer
{
get
{
return this.strWebResponseServer;
}
}
/// <summary>
/// This Property Is Used To Get Web Response StatusCode.
/// </summary>
public string WebResponseStatusCode
{
get
{
return this.strWebResponseStatusCode;
}
}
/// <summary>
/// This Property Is Used To Set Explicitly Http Response Data Local Copy File Name.
/// </summary>
public bool FileCopyLocationIncludesName
{
set
{
this.blnFileCopyLocationIncludesName = value;
}
}
#endregion
#region
Method Declaration
/// <summary>
/// This is the constructor of the class
/// </summary>
public HTTPResponseRequest()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// It's Used For Getting HTTP Data From The Web Server And Return HTTP Response.
/// </summary>
/// <param name="strURL">URL String To Fetch Data From Http Web Server.</param>
/// <returns>String Data Of HTTP Response From The Web Server.</returns>
public string HTTPGetData(string strURL)
{
//
this.strRequestMethod = GET;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.ProcessRequest(GET);
//
StreamReader streamreaderStreamReader = new StreamReader(this.responseStream);
//
return streamreaderStreamReader.ReadToEnd();
}
/// <summary>
/// It's Used For Getting HTTP Data From Web Server With Http Form Post Method And Return HTTP Response.
/// </summary>
/// <param name="strURL">URL String To Fetch Data From Http Web Server.</param>
/// <param name="hashtablePostData">Key-and-Value Pair For Multiple Data To Be Posted On The Web Server With Http Post Method.</param>
/// <returns>String Data Of HTTP Response From The Web Server.</returns>
public string HTTPPostData(string strURL, Hashtable hashtablePostData)
{
//
this.strRequestMethod = POST;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.hashtablePostData = hashtablePostData;
//
this.CreatePostData();
//
this.ProcessRequest(POST);
//
StreamReader streamreaderStreamReader = new StreamReader(this.responseStream);
//
return streamreaderStreamReader.ReadToEnd();
}
/// <summary>
/// It's Used For Getting HTTP Stream From The Web Server And Return HTTP Response.
/// </summary>
/// <param name="strURL">URL String To Fetch Data From Http Web Server.</param>
/// <returns>Stream Data Of HTTP Response From The Web Server.</returns>
public Stream HTTPGetStream(string strURL)
{
//
this.strRequestMethod = GET;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.ProcessRequest(GET);
//
return this.responseStream;
}
/// <summary>
/// It's Used For Getting HTTP Stream From Web Server With Http Form Post Method And Return HTTP Response.
/// </summary>
/// <param name="strURL">URL String To Fetch Data From Http Web Server.</param>
/// <param name="hashtablePostData">Key-and-Value Pair For Multiple Data To Be Posted On The Web Server With Http Post Method.</param>
/// <returns>Stream Data Of HTTP Response From The Web Server.</returns>
public Stream HTTPPostStream(string strURL, Hashtable hashtablePostData)
{
//
this.strRequestMethod = POST;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.hashtablePostData = hashtablePostData;
//
this.CreatePostData();
//
this.ProcessRequest(POST);
//
return this.responseStream;
}
/// <summary>
/// It's Used For Getting HTTP Data From Web Server And Saving It On Local File System.
/// </summary>
/// <param name="strUrl">URL String To Fetch Data From Http Web Server.</param>
/// <param name="strFileCopyLocation">Local File Location To Save HTTP Response Data.</param>
/// <returns>Status of Sucess or Failor.</returns>
public bool HTTPGetFileDownload(string strURL, string strFileCopyLocation)
{
//
this.strRequestMethod = GET;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.ProcessRequest(GET);
//
this.CreateLocalFile(strFileCopyLocation);
//
return true;
}
/// <summary>
/// It's Used For Getting HTTP Data From Web Server With Http Form Post Method And Saving It On Local File System.
/// </summary>
/// <param name="strUrl">URL String To Fetch Data From Http Web Server.</param>
/// <param name="strFileCopyLocation">Local File Location To Save HTTP Response Data.</param>
/// <param name="hashtablePostData">Key-and-Value Pair For Multiple Data To Be Posted On The Web Server With Http Post Method.</param>
/// <returns>Status of Sucess or Failor.</returns>
public bool HTTPPostFileDownLoad(string strURL, string strFileCopyLocation, Hashtable hashtablePostData)
{
//
this.strRequestMethod = POST;
//
this.strURL = strURL;
//
this.strRequestContentType = CONTENTTYPE;
//
this.hashtablePostData = hashtablePostData;
//
this.CreatePostData();
//
this.ProcessRequest(POST);
//
this.CreateLocalFile(strFileCopyLocation);
//
return true;
}
/// <summary>
/// It's Used For Uploading File & Data From Web Server With Http Form Post Method And Return HTTP Response.
/// </summary>
/// <param name="strURL">URL String To Fetch Data From Http Web Server.</param>
/// <param name="hashtablePostData">Key-and-Value Pair For Multiple File & Data To Be Posted On The Web Server With Http Post Method.</param>
/// <returns>String Data Of HTTP Response From The Web Server.</returns>
public string HTTPPostFileUpLoad(string strURL, Hashtable hashtablePostData)
{
//
this.strRequestMethod = POST;
//
this.strURL = strURL;
//
this.strRequestContentType = FILEUPLOADCONTENTTYPE + COLAN + BOUNDARY + EQUALTO + strFileUploadboundary;
//
this.hashtablePostData = hashtablePostData;
//
this.ProcessRequest(FILEUPLOAD);
//
StreamReader streamreaderStreamReader = new StreamReader(this.responseStream);
//
string strData = streamreaderStreamReader.ReadToEnd();
//
if (!object.Equals(this.responseStream, null)) this.responseStream.Close();
//
if (!object.Equals(this.response, null)) this.response.Close();
//
this.response.Close();
//
return strData;
}
#endregion
#region
Event Declaration
#endregion
#region
Helper Method Declaration
/// <summary>
/// This helper method is used to create the web request along with post or file upload header.
/// </summary>
/// <param name="strHeader"></param>
private void ProcessRequest(string strHeader)
{
//
this.request = (HttpWebRequest)HttpWebRequest.Create(this.strURL);
//pass Proxy string and bypass local machine
if (!object.Equals(this.strWebProxyUrl, null))
{
WebProxy loProxy = new WebProxy(this.strWebProxyUrl, true);
//
this.request.Proxy = loProxy;
}
//
this.request.Method = this.strRequestMethod;
//
this.request.KeepAlive = false;
//
this.request.ContentType = this.strRequestContentType;
//
if (!object.Equals(this.hashtableWebRequestHeader, null))
{
foreach (DictionaryEntry d in this.hashtableWebRequestHeader)
{
this.request.Headers.Add(d.Key.ToString(), d.Value.ToString());
}
}
if (!object.Equals(this.cookiecolWebRequestCookies, null))
{
//
CookieContainer cookieContainer = new CookieContainer();
//
cookieContainer.Add(
this.cookiecolWebRequestCookies);
//
this.request.CookieContainer = cookieContainer;
}
//
switch (strHeader)
{
case GET:
//
break;
case POST:
// Get the data that is being posted (or sent) to the server
byte[] bytes = Encoding.GetEncoding(1252).GetBytes(this.strPostData);
//System.Text.Encoding.ASCII.GetBytes (this.strData);
this.request.ContentLength = bytes.Length;
// 1. Get an output stream from the request object
Stream outputStream = request.GetRequestStream();
// 2. Post the data out to the stream
outputStream.Write(bytes, 0, bytes.Length);
// 3. Close the output stream and send the data out to the web server
outputStream.Close();
break;
case FILEUPLOAD:
//Calculates The content length of the uploaded data
this.CreateFileUploadData(null);
//Writes The Upload Data To RequestStream
this.CreateFileUploadData(this.request.GetRequestStream());
break;
default:
break;
}
//
this.response = (HttpWebResponse)request.GetResponse();
//
this.longResponseContentLength = this.response.ContentLength;
//
this.strResponseContentType = this.response.ContentType;
//
this.strResponseURL = this.response.ResponseUri.ToString();
//
for (int i = INT_ZERO; i < this.response.Headers.Count - 1; i++)
{
if (this.hashtableWebResponseHeader.ContainsKey(this.response.Headers.Keys[i]))
{
this.hashtableWebResponseHeader[this.response.Headers.Keys[i]] = this.response.Headers[i];
}
else
{
this.hashtableWebResponseHeader.Add(this.response.Headers.Keys[i], this.response.Headers[i]);
}
}
//
this.WebResponseCookies.Add(this.response.Cookies);
//
this.strWebResponseMethod = this.response.Method;
//
this.datetimeWebResponseContentLastModified = this.response.LastModified;
//
this.strWebResponseProtocolVersion = this.response.ProtocolVersion.ToString();
//
this.strWebResponseServer = this.response.Server;
//
this.strWebResponseStatusCode = this.response.StatusCode.ToString();
//
this.strWebResponseStatusDescription = this.response.StatusDescription;
//
this.strWebResponseCharacterSet = this.response.CharacterSet;
//
this.strWebResponseContentEncoding = this.response.ContentEncoding;
//
this.responseStream = this.response.GetResponseStream();
}
/// <summary>
/// This helper method is used for creating post form method header.
/// </summary>
private void CreatePostData()
{
//Creating Post Data String
foreach (DictionaryEntry d in this.hashtablePostData)
{
if (INT_ZERO == this.strPostData.Length)
{
this.strPostData = d.Key + EQUALTO + System.Web.HttpUtility.UrlEncode(d.Value.ToString());
}
else
{
this.strPostData += AMPERSTANT + d.Key + EQUALTO + System.Web.HttpUtility.UrlEncode(d.Value.ToString());
}
}
}
/// <summary>
/// This helper method creates the local copy of the http file.
/// </summary>
/// <param name="strFileCopyLocation"></param>
private void CreateLocalFile(string strFileCopyLocation)
{
//
if (!this.blnFileCopyLocationIncludesName)
{
//
string[] strFileName = this.strURL.Split(FORWARDSLASH);
//
strFileCopyLocation = strFileCopyLocation + BACKSLASH + strFileName[strFileName.Length - INT_ONE];
}
else
{
this.blnFileCopyLocationIncludesName = false;
}
//
Stream localStream = File.Create(strFileCopyLocation);
// Allocate a 1k buffer
byte[] buffer = new byte[BUFFERSIZE];
//
int bytesRead;
//
//int bytesProcessed = 0;
// Simple do/while loop to read from stream until
// no bytes are returned
while ((bytesRead = this.responseStream.Read(buffer, INT_ZERO, buffer.Length)) > INT_ZERO)
localStream.Write(buffer, INT_ZERO, bytesRead);
// do
// {
// // Read data (up to 1k) from the stream
//
//
// if(bytesRead > INT_ZERO)
// {
// // Write the data to the local file
// localStream.Write(buffer, INT_ZERO, bytesRead);
// // Increment total bytes processed
// bytesProcessed += bytesRead;
// }
// } while (bytesRead > INT_ZERO);
//
if (!object.Equals(localStream, null)) localStream.Close();
}
/// <summary>
/// This helper method is used for creating file upload header or calculate the content length.
/// </summary>
/// <param name="requestStream"></param>
private void CreateFileUploadData(Stream requestStream)
{
//
bool blnFileExists;
//
bool blnStatus;
//
long lngContentLength = 0;
//
if (requestStream != null)
{
blnStatus =
true;
}
else
{
blnStatus =
false;
}
//
int bytesRead = 0;
//
foreach (DictionaryEntry d in this.hashtablePostData)
{
blnFileExists =
File.Exists(d.Value.ToString());
// Build up the post message header
StringBuilder sb = new StringBuilder();
sb.Append(
this.strFileUploadboundary + FILEUPLOADLINEBREAKCHAR);
sb.Append(
"Content-Disposition: form-data");
sb.Append(COLAN);
sb.Append(
"name=\"" + d.Key + "\"");
if (blnFileExists)
{
sb.Append(COLAN);
//
sb.Append(
"filename=\"" + d.Value + "\"" + FILEUPLOADLINEBREAKCHAR);
//
//ReflectionPermission regPerm = new ReflectionPermission(System.Security.Permissions.RegistryPermissionAccess.Read);
//
RegistryKey classesRoot = Registry.ClassesRoot;
//
FileInfo fileinfo = new FileInfo(d.Value.ToString());
//
string fileextension = fileinfo.Extension.ToLower();
//
RegistryKey typekey = classesRoot.OpenSubKey(@"MIME\Database\Content Type");
//
foreach (string strKeyName in typekey.GetSubKeyNames())
{
//
RegistryKey curKey = classesRoot.OpenSubKey(@"MIME\Database\Content Type\" + strKeyName);
//
if (curKey.GetValue("Extension") == null)
{
}
else
{
if (curKey.GetValue("Extension").ToString().ToLower() == fileextension)
{
//
sb.Append(
"Content-Type: " + strKeyName + FILEUPLOADLINEBREAKCHAR + FILEUPLOADLINEBREAKCHAR);
//
break;
}
}
//
curKey.Close();
//
classesRoot.Close();
}
//
typekey.Close();
}
else
{
sb.Append(FILEUPLOADLINEBREAKCHAR + FILEUPLOADLINEBREAKCHAR);
}
//
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sb.ToString());
//
if (blnStatus)
{
// Write out our post header
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
}
//
byte[] buffer;
//
if (blnFileExists)
{
FileStream fileStream = new FileStream(d.Value.ToString(), FileMode.Open, FileAccess.Read);
//
byte[] linebreakbuffer = Encoding.UTF8.GetBytes(FILEUPLOADLINEBREAKCHAR);
//
if (blnStatus)
{
// Write out the file contents
buffer =
new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
//
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
requestStream.Write(buffer, 0, bytesRead);
//
requestStream.Write(linebreakbuffer, 0, linebreakbuffer.Length);
}
else
{
//
lngContentLength = lngContentLength + postHeaderBytes.Length + fileStream.Length + linebreakbuffer.Length;
}
//
fileStream.Close();
}
else
{
//
buffer =
Encoding.UTF8.GetBytes(d.Value + FILEUPLOADLINEBREAKCHAR);
if (blnStatus)
{
// Write out our Data
requestStream.Write(buffer, 0, buffer.Length);
}
else
{
//
lngContentLength = lngContentLength + postHeaderBytes.Length + buffer.Length;
}
}
}
// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryEndBytes = Encoding.ASCII.GetBytes(this.strFileUploadboundary + "--" + FILEUPLOADLINEBREAKCHAR);
//
if (blnStatus)
{
// Write out the trailing boundary
requestStream.Write(boundaryEndBytes, 0, boundaryEndBytes.Length);
//
requestStream.Close();
}
else
{
//
this.request.ContentLength = lngContentLength + boundaryEndBytes.Length;
}
}
#endregion
}
}
//Client Application to test the functionality
namespace
HttpWebRequestResponseClient
{
class Program
{
static void Main(string[] args)
{
AlladinHttpRequestResponse.
HTTPResponseRequest http = new AlladinHttpRequestResponse.HTTPResponseRequest();
Console.WriteLine(http.HTTPGetData("http://blogs.msdn.com/yasinalladin/default.aspx"));
http.HTTPGetFileDownload(
"http://blogs.msdn.com/yasinalladin/default.aspx", @"D:\HttpRequestResponse\HttpRequestResponse\HttpWebRequestResponseClient\Download");
System.Collections.
Hashtable hashtable = new System.Collections.Hashtable();
hashtable.Add(
"firstname", "Yasin Mukadam");
Console.WriteLine(http.HTTPPostData("http://localhost:50924/HttpRequestResponseWebClient/Default.aspx", hashtable));
Console.WriteLine(http.HTTPPostFileDownLoad("http://localhost:50924/HttpRequestResponseWebClient/Default.aspx",@"D:\HttpRequestResponse\HttpRequestResponse\HttpWebRequestResponseClient\Download" , hashtable).ToString());
Console.ReadLine();
}
}
}