HttpDownload class reference

 

 

 

 

Property string URL

 

        Source URL to be downloaded.

 

        When reading, the URL has the following form:

        http://hostname[:port]/(path)

        It always begins with "http://". Port is only specified when it is

        non-standard (not 80). "/" after hostname or port is always present,

        even if path is empty. Path is encoded using the "url-encode" method

        (some characters, like spaces, are escaped using %xx notation).

 

        When setting this property, only hostname is required.

 

        Note that setting this property when object is busy (download is in

        progress) has no effect.

 

Property string DestinationFile

 

        File to write the downloaded object to.

 

        If this property is set to an empty string, the webpage will be

        downloaded to memory and will be accessible throught ResponseBody

        property.

 

        Error responses (not 2xx) are always downloaded to memory.

 

        If the specified file already exists, it will be overwritten.

 

        Note that setting this property when object is busy (download is in

        progress) has no effect.

 

Property uint TimeOut

 

        Timeout value in milliseconds.

 

        If the timeout elapses and the download has not completed yet, the

        reponse code will be set to -1.

        The value of 0 means no timeout.

 

        Note that setting this property when object is busy (download is in

        progress), has no effect.

 

Property int ResponseCode

 

        Response code as received from the server or -1 on error/timeout.

 

        Value of this property is undefined when the download is in progress.

 

Property string ResponseBody

 

        Body of the response returned by the server.

 

        If the download succeeds and DestinationFile was not an empty string,

        value of this property is not defied - the actual response body is

        written to the DestinationFile.

 

        This property is inteded for use with text webpages - for example

        it converts text to Unicode. Thus it may not reflect to the actual

        data received from the server. When raw binary data is required (for

        instance when downloading an image) it is strongly recommended to

        save it to a file (see DestinationFile).

 

        While reading this property, the string representing the response body

        is converted from ANSI to Unicode (this involves memory allocation,

        deallocation, copying, etc...) thus this function is not very fast.

        For performance critical applications it is recommended to assign value

        of this property to a temporary variable, like this:

 

        string responseBody = httpDownload.ResponseBody;

        // do something with responseBody

        // do something more with responseBody...

        // etc...

 

Method void SetHttpProxy(string Host, ushort Port)

 

        Sets the host and port of an HTTP proxy to use.

 

        If host is an empty string, no proxy will be used.

        Proxy information is kept after the download is complete/fails, so

        this functions does not have to be called before each download.

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void SetAuthData(string Username, string Password)

 

        Sets athentication data to be used when contacting the server.

 

        Authorization data is reset after each download (either successful or not).

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void AddFormHeader(string Name, string Value)

 

        Adds a form header.

 

        Form headers are sent using GET or POST depending on which method has

        been chosen (see SetMethodGET() and SetMethodPOST()).

 

        Name and/or Value may contain characters that are not normally allowed

        in the URI - they will be encoded using the %xx notation.

 

        Name and Value have such meaning that, when using GET method, they

        will be encoded into the URL as ?Name1=Value1&Name2=Value2... etc.

 

        Authorization data is reset after each download (either successful or not).

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void AddRequestHeader(string Name, string Value)

 

        Adds a request header.

 

        Name and Value have such meaning that they will be incorporated into

        the request as "Name: Value\r\n"

 

        The only headers added by default are:

        - "Host" - required by the HTTP/1.1 protocol specification (RFC2616)

        - "Authorization" - when using basic authorization (see SetAuthData())

        - "Content-Length" & "Content-Type" - when sending form headers using POST

        - “Accept-Encoding” – to indicate that the client supports gzip and deflate encoding

        - “Connection” – to request a persistent connection (speeds up subsequent

            downloads from the same server)

 

        Headers added using this function are discarded after each download.

        To specify headers that will not be discarded, use AddRequestHeaderPersistent().

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void AddRequestHeaderPersistent(string Name, string Value)

 

        Adds a request header that will not be discarded after each download.

 

        Name and Value have such meaning that they will be incorporated into

        the request as "Name: Value\r\n"

 

        The only headers added by default are:

        - "Host" - required by the HTTP/1.1 protocol specification (RFC2616)

        - "Authorization" - when using basic authorization (see SetAuthData())

        - "Content-Length" & "Content-Type" - when sending form headers using POST

        - “Accept-Encoding” – to indicate that the client supports gzip and deflate encoding

        - “Connection” – to request a persistent connection (speeds up subsequent

            downloads from the same server)

 

        This function is suitable for adding headers like "User-Agent", etc..

 

        Note that calling this function when download is in progress has

        no effect.

 

Method string GetResponseHeader(string Name)

 

        Get value of a particular response header.

 

        If the specified header was not present in the last server response

        an empty string will be returned.

 

        This function is not guaranteed to give valid results when download

        is in progress.

 

Method void EnumFirstResponseHeader(out string Name, out string Value)

 

        Enumerate response headers (begin).

 

        Resets the internal iterator to the initial position and returns

        name and value of the first response headers. If no headers have

        been received, both name and value will be empty strings.

 

        EnumFirstResponseHeader() and EnumNextResponseHeader() functions

        does not necessarily return headers in the same order they have been

        received from the server.

 

        See EnumNextResponseHeader for example code showing how to enumerate

        response headers.

 

        This function is not guaranteed to give correct results when download

        is in progress.

 

Method void EnumNextResponseHeader(out string Name, out string Value)

 

        Enumerate response headers (continue).

 

        Returns name and value of the next response header or empty strings

        if there are no more headers.

 

        EnumFirstResponseHeader() and EnumNextResponseHeader() functions

        does not necessarily return headers in the same order they have been

        received from the server.

 

        This function is not guaranteed to give correct results when download

        is in progress.

 

        Example use (C#):

 

        string name, val;

        download.EnumFirstResponseHeader(out name, out val);

        while(name != "") {

                // do something with name & val

                download.EnumNextResponseHeader(out name, out val);

        }

 

Method void SetMethodGET()

 

        Tells the object to use GET method for the next download (this is the default).

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void SetMethodPOST()

 

        Tells the object to use POST method for the next download.

 

        After download is complete or fails, method is reset to GET.

 

        Note that calling this function when download is in progress has

        no effect.

 

Method void StartAsync()

 

        Starts asynchronous download.

 

        This method initiates download process and returns immediatelly. When

        the download is complete, fails or times out, DownloadFinished event

        is signaled.

 

        This method should not be called when using HttpDownloadManager class.

 

        Note that calling this function when download is already in progress has

        no effect.

 

Method void StartBlocking()

 

        Starts synchronous download.

 

        This method initiates download process and blocks till it completes,

        fails or times out. DownloadFinished event is signaled upon return.

 

        This method should not be called when using HttpDownloadManager class.

 

        Note that calling this function when download is already in progress has

        no effect.

 

Method void Reset()

 

        Resets object to the initial state.

 

        Everything is set as it would be if the object was destroyed and recreated.

 

        Note that calling this function when download is already in progress has

        no effect.

 

Method void EnableKeepAlive()

 

        Enables sending of 'Connection: Keep-Alive' request header.

        This is the deafault.

 

        Note that calling this function when download is already in progress has

        no effect.

 

Method void DisableKeepAlive()

 

        Disables sending of 'Connection: Keep-Alive' request header. Instead

        'Connection: close' will be send.

 

        Note that calling this function when download is already in progress has

        no effect.

 

Property bool PersistForm

 

        If a request to a page that redirects is made and this property is set to

        true, the form values will be passed to any subsequent pages. Otherwise

        they will be passed only to the first one.

        The default value is true.

 

        Note that setting this property when object is busy (download is in

        progress), has no effect.

 

Property bool PersistForm

 

        If a request to a page that redirects is made and this property is set to

        true, the downloader will follow the redirect. Otherwise DownloadFinished

        event will be raised and RedirectURL property will hold the redirected URL

        (if any).

        The default value is true.

 

        Note that setting this property when object is busy (download is in

        progress), has no effect.

 

Property bool PersistForm

 

        If FollowRedirects is false and a request to a page that redirects has been

        made, this will contain the URL specified in the Location header provided

        by the server (the URL the page redirected to).

 

        Note that setting this property when object is busy (download is in

        progress), has no effect.

 

 

This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit (http://www.openssl.org/). This product includes cryptographic software written by Eric Young (eay@cryptsoft.com). This product includes software written by Tim Hudson (tjh@cryptsoft.com). For more information see OpenSSL_license.txt.