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.
Westwind.Utilities.InternetTools.HttpClient
public class HttpClient : object, IDisposable
Class Members
Member | Description | |
---|---|---|
Constructor |
The HttpClient Default Constructor | |
ReceiveData |
Fires progress events when receiving data from the server | |
SendData |
Fires progress events when using GetUrlEvents() to retrieve a URL. | |
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 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) |
|
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. public bool CreateWebRequestObject(string Url) |
|
DownloadBytes |
Retrieves URL into an Byte Array. public Byte[] DownloadBytes(string url, long bufferSize) |
|
DownloadBytesAsync |
Retrieves URL into an Byte Array. public Task<Byte[]> 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 results further. public HttpWebResponse DownloadResponse(string url) |
|
DownloadResponseAsync |
public Task |
|
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 |
|
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 at the top of the page. Also returns full headers. public string DownloadStringPartial(string url, int size) |
|
GetPostBuffer |
Returns the contents of the post buffer. Useful for debugging public string GetPostBuffer() |
|
ResetPostData |
Resets the Post buffer by clearing out all existing content public void ResetPostData() |
|
SetPostStream |
public void SetPostStream(Stream postStream) |
|
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. | |
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 request. | |
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. | |
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. | |
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). | |
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 . | |
WebResponse |
WebResponse object that is accessible after the request is complete and allows you to retrieve additional information about the completed request. |
Requirements
Namespace: Westwind.Utilities.InternetToolsAssembly: westwind.utilities.dll
© West Wind Technologies, 1996-2024 • Updated: 06/29/24
Comment or report problem with topic