Library: Net
Package: HTML
Header: Poco/Net/HTMLForm.h
HTMLForm is a helper class for working with HTML forms, both on the client and on the server side.
The maximum number of form fields can be restricted by calling setFieldLimit(). This is useful to defend against certain kinds of denial-of-service attacks. The limit is only enforced when parsing form data from a stream or string, not when adding form fields programmatically. The default limit is 100.
Direct Base Classes: NameValueCollection
All Base Classes: NameValueCollection
Member Functions: addPart, boundary, getEncoding, getFieldLimit, load, prepareSubmit, read, readMultipart, readUrl, setEncoding, setFieldLimit, write, writeMultipart, writeUrl
Inherited Functions: add, begin, clear, empty, end, erase, find, get, has, operator =, operator [], set, size, swap
HTMLForm();
Creates an empty HTMLForm and sets the encoding to "application/x-www-form-urlencoded".
explicit HTMLForm(
const std::string & encoding
);
Creates an empty HTMLForm that uses the given encoding.
Encoding must be either "application/x-www-form-urlencoded" (which is the default) or "multipart/form-data".
explicit HTMLForm(
const HTTPRequest & request
);
Creates a HTMLForm from the given HTTP request.
The request must be a GET request and the form data must be in the query string (URL encoded).
For POST requests, you must use one of the constructors taking an additional input stream for the request body.
HTMLForm(
const HTTPRequest & request,
std::istream & requestBody
);
Creates a HTMLForm from the given HTTP request.
Uploaded files are silently discarded.
HTMLForm(
const HTTPRequest & request,
std::istream & requestBody,
PartHandler & handler
);
Creates a HTMLForm from the given HTTP request.
Uploaded files are passed to the given PartHandler.
~HTMLForm();
Destroys the HTMLForm.
void addPart(
const std::string & name,
PartSource * pSource
);
Adds an part/attachment (file upload) to the form.
The form takes ownership of the PartSource and deletes it when it is no longer needed.
The part will only be sent if the encoding set for the form is "multipart/form-data"
const std::string & boundary() const;
Returns the MIME boundary used for writing multipart form data.
const std::string & getEncoding() const;
Returns the encoding used for posting the form.
int getFieldLimit() const;
Returns the maximum number of header fields allowed.
See setFieldLimit() for more information.
void load(
const HTTPRequest & request,
std::istream & requestBody,
PartHandler & handler
);
Reads the form data from the given HTTP request.
Uploaded files are passed to the given PartHandler.
void load(
const HTTPRequest & request,
std::istream & requestBody
);
Reads the form data from the given HTTP request.
Uploaded files are silently discarded.
void load(
const HTTPRequest & request
);
Reads the form data from the given HTTP request.
The request must be a GET request and the form data must be in the query string (URL encoded).
For POST requests, you must use one of the overloads taking an additional input stream for the request body.
void prepareSubmit(
HTTPRequest & request
);
Fills out the request object for submitting the form.
If the request method is GET, the encoded form is appended to the request URI as query string. Otherwise (the method is POST), the form's content type is set to the form's encoding. The form's parameters must be written to the request body separately, with a call to write. If the request's HTTP version is HTTP/1.0:
Otherwise, if the request's HTTP version is HTTP/1.1:
void read(
std::istream & istr,
PartHandler & handler
);
Reads the form data from the given input stream.
The form data read from the stream must be in the encoding specified for the form.
Note that read() does not clear the form before reading the new values.
void read(
std::istream & istr
);
Reads the URL-encoded form data from the given input stream.
Note that read() does not clear the form before reading the new values.
void read(
const std::string & queryString
);
Reads the form data from the given HTTP query string.
Note that read() does not clear the form before reading the new values.
void setEncoding(
const std::string & encoding
);
Sets the encoding used for posting the form.
Encoding must be either "application/x-www-form-urlencoded" (which is the default) or "multipart/form-data".
void setFieldLimit(
int limit
);
Sets the maximum number of header fields allowed. This limit is used to defend certain kinds of denial-of-service attacks. Specify 0 for unlimited (not recommended).
The default limit is 100.
void write(
std::ostream & ostr,
const std::string & boundary
);
Writes the form data to the given output stream, using the specified encoding.
void write(
std::ostream & ostr
);
Writes the form data to the given output stream, using the specified encoding.
void readMultipart(
std::istream & istr,
PartHandler & handler
);
void readUrl(
std::istream & istr
);
void writeMultipart(
std::ostream & ostr
);
void writeUrl(
std::ostream & ostr
);
static const std::string ENCODING_MULTIPART;
"multipart/form-data"
static const std::string ENCODING_URL;
"application/x-www-form-urlencoded"