HttpPost

Supports the basic needs of a client sending POST requests to a HTTP server. The following is a usage example:

// open a web-page for posting (see HttpGet for simple reading)
auto post = new HttpPost ("http://yourhost/yourpath");

// send, retrieve and display response
Cout (cast(char[]) post.write("posted data", "text/plain"));

Constructors

this
this(const(char)[] url)

Create a client for the given URL. The argument should be fully qualified with an "http:" or "https:" scheme, or an explicit port should be provided.

this
this(Uri uri)

Create a client with the provided Uri instance. The Uri should be fully qualified with an "http:" or "https:" scheme, or an explicit port should be provided.

Members

Functions

write
void[] write()

Send query params only

write
void[] write(Pump pump)

Send raw data via the provided pump, and no query params. You have full control over headers and so on via this method.

write
void[] write(const(void)[] content, const(char)[] type)

Send content and no query params. The contentLength header will be set to match the provided content, and contentType set to the given type.

Inherited Members

From HttpClient

Pump
alias Pump = void delegate(OutputBuffer)

callback for sending PUT content

Version
enum Version
Undocumented in source.
Get
RequestMethod Get;
Put
RequestMethod Put;
Head
RequestMethod Head;
Post
RequestMethod Post;
Trace
RequestMethod Trace;
Delete
RequestMethod Delete;
Options
RequestMethod Options;
Connect
RequestMethod Connect;
Undocumented in source.
getResponseHeaders
HttpHeadersView getResponseHeaders()

Get the current input headers, as returned by the host request.

getRequestHeaders
HttpHeaders getRequestHeaders()

Gain access to the request headers. Use this to add whatever headers are required for a request.

getRequestParams
HttpParams getRequestParams()

Gain access to the request parameters. Use this to add x=y style parameters to the request. These will be appended to the request assuming the original Uri does not contain any of its own.

getUri
UriView getUri()

Return the Uri associated with this client

getResponse
ResponseLine getResponse()

Return the response-line for the latest request. This takes the form of "version status reason" as defined in the HTTP RFC.

getStatus
int getStatus()

Return the HTTP status code set by the remote server

isResponseOK
bool isResponseOK()

Return whether the response was OK or not

addCookie
HttpClient addCookie(Cookie cookie)

Add a cookie to the outgoing headers

close
void close()

Close all resources used by a request. You must invoke this between successive open() calls.

reset
HttpClient reset()

Reset the client such that it is ready for a new request.

setRequest
HttpClient setRequest(RequestMethod method)

Set the request method

setVersion
HttpClient setVersion(Version v)

Set the request version

enableRedirect
HttpClient enableRedirect(bool yes)

enable/disable the internal redirection suppport

setTimeout
HttpClient setTimeout(float interval)

set timeout period for read operation

keepAlive
HttpClient keepAlive(bool yes)

Control keepalive option

encodeUri
HttpClient encodeUri(bool yes)

Control Uri output encoding

open
InputBuffer open()

Make a request for the resource specified via the constructor, using the specified timeout period (in milli-seconds).The return value represents the input buffer, from which all returned headers and content may be accessed.

open
InputBuffer open(Pump pump)

Make a request for the resource specified via the constructor, using a callback for pumping additional data to the host. This defaults to a three-second timeout period. The return value represents the input buffer, from which all returned headers and content may be accessed.

open
InputBuffer open(RequestMethod method, Pump pump)

Make a request for the resource specified via the constructor using the specified timeout period (in micro-seconds), and a user-defined callback for pumping additional data to the host. The callback would be used when uploading data during a 'put' operation (or equivalent). The return value represents the input buffer, from which all returned headers and content may be accessed.

read
void read(void delegate(const(void)[]) sink, size_t len)

Read the content from the returning input stream, up to a maximum length, and pass content to the given sink delegate as it arrives.

redirectPost
InputBuffer redirectPost(Pump pump, int status)

Handle redirection of Post

canRepost
bool canRepost(uint status)

Handle user-notification of Post redirection. This should be overridden appropriately.

createSocket
Socket createSocket()

Overridable socket factory, for use with HTTPS and so on

Meta