Internet Direct (Indy) Version 9.0.1 Beta
TIdHTTP.DoRequest
Performs a HTTP request and retrieves the HTTP response.

procedure DoRequest(const AMethod: TIdHTTPMethod; AURL: string; const ASource: TStream; const AResponseContent: TStream); virtual;
Parameters
const AMethod: TIdHTTPMethod
The HTTP method to perform.

AURL: string
The location of the resource.

const ASource: TStream
Source of the Request data.

const AResponseContent: TStream
Destination for the Response content.

Description
DoRequest is a procedure used to implement and execute a HTTP request and retrieve the HTTP response. DoRequest is used in the Get, Head, Post, Put, and Trace methods to perform HTTP transfers. DoRequest recognizes the HTTP methods represented in TIdHTTPMethod, but checks to insure that ProtocolVersion indicates HTTP 1.1 for the hmTrace, hmPut, hmOptions, and hmDelete methods. An exception will be raised if HTTP 1.1 methods are used when the Proctocol version indicates HTTP 1.0.

AMethod is the TIdHTTPMethod value that identifies the request to be performed. AURL is the URL-encode location of the resource to be affected by the HTTP request. ASource is a TObject descendant containing the data for the HTTP request. ASource must be either a TStrings or a TStream descendant or an EIdObjectTypeNotSupported exception will be raised. AResponseContent is a TStream where the content for the HTTP response will be stored.

DoRequest will parse AURL into components to determine if the URL contains a user name and password that should be used for authenticating the Request. DoRequest also normalizes the value in AURL to conform to URI notation.

DoRequest will call Connect when the client is not already Connected, and can raise a EIdSSLProtocolReplyError when using HTTPS and the connection fails or a timeout occurs.

DoRequest sets the content length of the Request to the size of the stream specified in ASource for HTTP PUT or POST methods, or zero (0) when using other HTTP methods. DoRequest also updates headers and optional cookies for the Request. DoRequest calls OpenWriteBuffer prior to construct and sending the HTTP Request to accomodate HTTP servers which do not fully implement the HTTP Protocol, and calls CloseWriteBuffer to complete the write transaction.

DoRequest reads the HTTP Server Response for the HTTP Client Request. DoRequest repeatedly calls ReadLn to retrieve headers and ResponseText from the server, until the server returns a ResponseCode other 100 Continue. This allows the HTTP client to accomodate servers which do not fully implement HTTP 1.1, and respond with 100 Continue for HTTP GET and HEAD methods.

DoRequest detects an HTTP Response with Redirection that requires further action to fulfill the Request. When HandleRedirects is True, and the current number of Redirects is less than the value specified in RedirectMaximum, AResponseContent is cleared and the OnRedirect event handler is triggered. Use OnRedirect to close the connection if no further processing is desired for the HTTP Response. When HandleRedirects is False, or RedirectMaximum is exceeded, the OnRedirect event handler is still triggered. An EIdProtocolReplyError can be raised when the redirect action is not handled in the OnRedirect event handler.

DoRequest also triggers event handlers when the HTTP ResponseCode indicates that HTTP Server or Proxy Server authentication is required for the HTTP Response. If the authentication is handled by the OnAuthorization or OnProxyAuthorization event handlers, DoRequest is called to perform the authentication request.