C# Класс Westwind.Utilities.InternetTools.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.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AddPostFile ( string key, string fileName ) : bool

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

AddPostKey ( byte fullPostBuffer ) : void

Adds a fully self contained POST buffer to the request. Works for XML or previously encoded content.

AddPostKey ( string fullPostBuffer ) : void

Adds a fully self contained POST buffer to the request. Works for XML or previously encoded content.

AddPostKey ( string key, byte value ) : void

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

AddPostKey ( string key, string value ) : void

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

CreateWebRequestObject ( string Url ) : bool

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 you can then pass null. Note - You need a new Web Request for each and every request so you need to set this object for every call if you manually customize it.

Dispose ( ) : void

Releases response and request data

DownloadBytes ( string url, long bufferSize = 8192 ) : byte[]

Retrieves URL into an Byte Array.

Fires the ReceiveData Event

DownloadBytesAsync ( string url, long bufferSize = 8192 ) : Task

Retrieves URL into an Byte Array.

Fires the ReceiveData Event

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

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

DownloadResponse ( string url ) : HttpWebResponse

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.

Important: The Response object's Close() method must be called when you are done with the object.

DownloadResponseAsync ( string url ) : Task
DownloadStream ( string url ) : StreamReader

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

DownloadString ( string url, long bufferSize = 8192, Encoding encoding = null ) : string

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

DownloadStringAsync ( string url, long bufferSize = 8192, Encoding encoding = null ) : Task

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

DownloadStringPartial ( string url, int size ) : string

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.

HttpClient ( ) : System

The HttpClient Default Constructor

ResetPostData ( ) : void

Resets the Post buffer by clearing out all existing content

SetPostStream ( Stream postStream ) : void

Защищенные методы

Метод Описание
StreamPostBuffer ( Stream PostData ) : void

Sends the Postbuffer to the server

Приватные методы

Метод Описание
CheckCertificateCallback ( object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors ) : bool

Handles the Certificate check

GetUrl ( string url, long bufferSize = 8192, Encoding encoding = null ) : string
GetUrlBytes ( string url, long bufferSize = 8192 ) : byte[]
GetUrlFile ( string Url, long BufferSize, string OutputFile ) : bool
GetUrlPartial ( string url, int size ) : string
GetUrlResponse ( string url ) : HttpWebResponse
GetUrlStream ( string Url ) : StreamReader

Описание методов

AddPostFile() публичный Метод

Allows posting a file to the Web Server. Make sure that you set PostMode
public AddPostFile ( string key, string fileName ) : bool
key string
fileName string
Результат bool

AddPostKey() публичный Метод

Adds a fully self contained POST buffer to the request. Works for XML or previously encoded content.
public AddPostKey ( byte fullPostBuffer ) : void
fullPostBuffer byte Byte array of a full POST buffer
Результат void

AddPostKey() публичный Метод

Adds a fully self contained POST buffer to the request. Works for XML or previously encoded content.
public AddPostKey ( string fullPostBuffer ) : void
fullPostBuffer string String based full POST buffer
Результат void

AddPostKey() публичный Метод

Adds POST form variables to the request buffer. PostMode determines how parms are handled.
public AddPostKey ( string key, byte value ) : void
key string Key value or raw buffer depending on post type
value byte Value to store. Used only in key/value pair modes
Результат void

AddPostKey() публичный Метод

Adds POST form variables to the request buffer. PostMode determines how parms are handled.
public AddPostKey ( string key, string value ) : void
key string Key value or raw buffer depending on post type
value string Value to store. Used only in key/value pair modes
Результат void

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 you can then pass null. Note - You need a new Web Request for each and every request so you need to set this object for every call if you manually customize it.
public CreateWebRequestObject ( string Url ) : bool
Url string
Результат bool

Dispose() публичный Метод

Releases response and request data
public Dispose ( ) : void
Результат void

DownloadBytes() публичный Метод

Retrieves URL into an Byte Array.
Fires the ReceiveData Event
public DownloadBytes ( string url, long bufferSize = 8192 ) : byte[]
url string Url to read
bufferSize long Size of the buffer for each read. 0 = 8192
Результат byte[]

DownloadBytesAsync() публичный Метод

Retrieves URL into an Byte Array.
Fires the ReceiveData Event
public DownloadBytesAsync ( string url, long bufferSize = 8192 ) : Task
url string Url to read
bufferSize long Size of the buffer for each read. 0 = 8192
Результат Task

DownloadFile() публичный Метод

Writes the output from the URL request to a file firing events.
public DownloadFile ( string url, long bufferSize, string outputFile ) : bool
url string Url to fire
bufferSize long Buffersize - how often to fire events
outputFile string File to write response to
Результат bool

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.
Important: The Response object's Close() method must be called when you are done with the object.
public DownloadResponse ( string url ) : HttpWebResponse
url string Url to retrieve.
Результат HttpWebResponse

DownloadResponseAsync() публичный Метод

public DownloadResponseAsync ( string url ) : Task
url string
Результат 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 DownloadStream ( string url ) : StreamReader
url string Url to retrieve.
Результат StreamReader

DownloadString() публичный Метод

Returns the content of a URL as a string using a specified Encoding
public DownloadString ( string url, long bufferSize = 8192, Encoding encoding = null ) : string
url string
bufferSize long Internal download buffer size used to hold data chunks.
encoding Encoding A .NET Encoding scheme or null to attempt sniffing from Charset.
Результат string

DownloadStringAsync() публичный Метод

Returns the content of a URL as a string using a specified Encoding
public DownloadStringAsync ( string url, long bufferSize = 8192, Encoding encoding = null ) : Task
url string
bufferSize long Internal download buffer size used to hold data chunks.
encoding Encoding A .NET Encoding scheme or null to attempt sniffing from Charset.
Результат 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 DownloadStringPartial ( string url, int size ) : string
url string
size int
Результат string

HttpClient() публичный Метод

The HttpClient Default Constructor
public HttpClient ( ) : System
Результат System

ResetPostData() публичный Метод

Resets the Post buffer by clearing out all existing content
public ResetPostData ( ) : void
Результат void

SetPostStream() публичный Метод

public SetPostStream ( Stream postStream ) : void
postStream Stream
Результат void

StreamPostBuffer() защищенный Метод

Sends the Postbuffer to the server
protected StreamPostBuffer ( Stream PostData ) : void
PostData Stream
Результат void