Class HttpClient

An HTTP wrapper class that abstracts away the common needs for adding post keys and firing update events as data is received. This class is real easy to use with many common operations requiring single method calls.

The class also provides automated cookie and state handling, GZip compression decompression, simplified proxy and authentication mechanisms to provide a simple single level class interface. The underlying WebRequest is also exposed so you will not loose any functionality from the .NET BCL class.

public class HttpClient : object

Class Members



The HttpClient Default Constructor


Fires progress events when receiving data from the server


Fires progress events when using GetUrlEvents() to retrieve a URL.


Allows posting a file to the Web Server. Make sure that you set PostMode

public bool AddPostFile(string key,     string fileName)


Adds POST form variables to the request buffer. PostMode determines how parms are handled.

public void AddPostKey(string key,     Byte[] value)

public void AddPostKey(string key,     string value)

public void AddPostKey(string fullPostBuffer)

public void AddPostKey(Byte[] fullPostBuffer)


Creates a new WebRequest instance that can be set prior to calling the various Get methods. You can then manipulate the WebRequest property, to custom configure the request.

public bool CreateWebRequestObject(string Url)


Retrieves URL into an Byte Array.

public Byte[] DownloadBytes(string url,     long bufferSize)


Writes the output from the URL request to a file firing events.

public bool DownloadFile(string url,     long bufferSize,     string outputFile)


Return an HttpWebResponse object for a request. You can use the Response to read the result as needed. This is a low level method. Most of the other 'Get' methods call this method and process the results further.

public HttpWebResponse DownloadResponse(string url)


Return a the result from an HTTP Url into a StreamReader. Client code should call Close() on the returned object when done reading.

public StreamReader DownloadStream(string url)


Returns the content of a URL as a string using a specified Encoding

public string DownloadString(string url,     long bufferSize,     Encoding encoding)


Returns a partial response from the URL by specifying only given number of bytes to retrieve. This can reduce network traffic and keep string formatting down if you are only interested a small port at the top of the page. Also returns full headers.

public string DownloadStringPartial(string url,     int size)


Resets the Post buffer by clearing out all existing content

public void ResetPostData()


public void SetPostStream(Stream postStream)


The buffersize used for the Send and Receive operations


Returns whether the last request was cancelled through one of the events.


Use this option to set a custom content type. If possible use PostMode to specify a predefined content type as it will ensure that Post data is appropriately formatted.


Holds the internal Cookie collection before or after a request. This collection is used only if HandleCookies is set to .t. which also causes it to capture cookies and repost them on the next request.


Error flag if an error occurred.


Error Message if the Error Flag is set or an error value is returned from a method.


If set to true will automatically track cookies between multiple successive requests on this instance. Uses the CookieCollection property to persist cookie status.


Keeps track of request timings for the last executed request. Tracks started, firstbyte and lastbyte times as well as ms to first byte (actually first 'buffer' loaded) and last byte.


Sets the certificate policy.


Password for Authentication.


Determines how data is POSTed when when using AddPostKey() and other methods of posting data to the server. Support UrlEncoded, Multi-Part, XML and Raw modes.


Address of the Proxy Server to be used. Use optional DEFAULTPROXY value to specify that you want to IE's Proxy Settings


Semicolon separated Address list of the servers the proxy is not used for.


Password for a password validating Proxy. Only used if the proxy info is set.


Username for a password validating Proxy. Only used if the proxy info is set.


Determines whether errors cause exceptions to be thrown. By default errors are handled in the class and the Error property is set for error conditions. (not implemented at this time).


Timeout for the Web request in seconds. Times out on connection, read and send operations. Default is 30 seconds.


Determines whether requests attempt to use GZip when retrieving content from the server.


Lets you specify the User Agent browser string that is sent to the server. This allows you to simulate a specific browser if necessary.


User name used for Authentication. To use the currently logged in user when accessing an NTLM resource you can use "AUTOLOGIN".


WebRequest object that can be manipulated and set up for the request if you called .


WebResponse object that is accessible after the request is complete and allows you to retrieve additional information about the completed request.


Namespace: Westwind.Utilities.InternetTools
Assembly: westwind.utilities.dll

© West Wind Technologies, 1996-2016 • Updated: 12/12/15
Comment or report problem with topic