HttpClient Class

Implements: IDisposable

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.

System.Object
   Westwind.Utilities.InternetTools.HttpClient

Class Members

MemberDescription
Constructor The HttpClient Default Constructor
ReceiveDataDelegate
ReceiveDataDelegate
AddPostFile Allows posting a file to the Web Server. Make sure that you set PostMode
public bool AddPostFile(string key, string fileName, string contentType)
AddPostKey Adds a fully self contained POST buffer to the request. Works for XML or previously encoded content.
public void AddPostKey(string key, byte[] value)
CreateWebRequestObject 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. Instead of passing a URL…
public bool CreateWebRequestObject(string Url)
Dispose Releases response and request data
public void Dispose()
DownloadBytes Retrieves URL into an Byte Array.
public byte[] DownloadBytes(string url, long bufferSize)
DownloadBytesAsync Retrieves URL into an Byte Array.
public Task DownloadBytesAsync(string url, long bufferSize)
DownloadFile Writes the output from the URL request to a file firing events.
public bool DownloadFile(string url, long bufferSize, string outputFile)
DownloadResponse 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…
public HttpWebResponse DownloadResponse(string url)
DownloadResponseAsync
public Task DownloadResponseAsync(string url)
DownloadStream 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)
DownloadString Returns the content of a URL as a string using a specified Encoding
public string DownloadString(string url, long bufferSize, Encoding encoding)
DownloadStringAsync Returns the content of a URL as a string using a specified Encoding
public Task DownloadStringAsync(string url, long bufferSize, Encoding encoding)
DownloadStringPartial 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…
public string DownloadStringPartial(string url, int size)
GetPostBuffer Returns the contents of the post buffer. Useful for debugging
public string GetPostBuffer()
GetUrl Returns the content of a URL as a string
public string GetUrl(string url, long bufferSize, Encoding encoding)
GetUrlFile Writes the output from the URL request to a file firing events.
public bool GetUrlFile(string Url, long BufferSize, string OutputFile)
GetUrlPartial 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…
public string GetUrlPartial(string url, int size)
GetUrlResponse 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…
public HttpWebResponse GetUrlResponse(string url)
ResetPostData Resets the Post buffer by clearing out all existing content
public void ResetPostData()
SetPostStream
public void SetPostStream(Stream postStream)
StreamPostBuffer Sends the Postbuffer to the server
public void StreamPostBuffer(Stream PostData)
BufferSize The buffersize used for the Send and Receive operations
Cancelled Returns whether the last request was cancelled through one of the events.
ContentType 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. If setting the content type…
Cookies 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…
Error Error flag if an error occurred.
ErrorMessage Error Message if the Error Flag is set or an error value is returned from a method.
HandleCookies If set to true will automatically track cookies between multiple successive requests on this instance. Uses the CookieCollection property to persist cookie status. When set posts values in the…
HttpTimings 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.
HttpVerb
IgnoreCertificateErrors Sets the certificate policy. Note this is a global setting and affects the entire application. It's recommended you set this for the application and not on a per request basis.
Password Password for Authentication.
PostMode 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.
ProxyAddress Address of the Proxy Server to be used. Use optional DEFAULTPROXY value to specify that you want to IE's Proxy Settings
ProxyBypass Semicolon separated Address list of the servers the proxy is not used for.
ProxyPassword Password for a password validating Proxy. Only used if the proxy info is set.
ProxyUsername Username for a password validating Proxy. Only used if the proxy info is set.
ThrowExceptions 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 Timeout for the Web request in seconds. Times out on connection, read and send operations. Default is 30 seconds.
TimeoutMs Timeout for the Web request in seconds. Times out on connection, read and send operations. Default is 30 seconds (30,000ms).
UseGZip When true will automatically add Accept-Encoding: gzip,deflate header and automatically decompress gzip and deflate content
UserAgent Lets you specify the User Agent browser string that is sent to the server. This allows you to simulate a specific browser if necessary.
Username User name used for Authentication. To use the currently logged in user when accessing an NTLM resource you can use "AUTOLOGIN".
WebRequest WebRequest object that can be manipulated and set up for the request if you called . Note: This object must be recreated and reset for each request, since a request's life time is tied to a single…
WebResponse WebResponse object that is accessible after the request is complete and allows you to retrieve additional information about the completed request. The Response Stream is already closed after the…
Namespace: Westwind.Utilities.InternetTools

Assembly: Westwind.Utilities.dll