|Did you know ...||Search Documentation:|
|Title for pldoc(object(section(3,'3.13',swi('/doc/packages/http.html'))))|
Name(Value)elements. It provides a number of predefined elements for the result of parsing the first line of the request, followed by the additional request parameters. The predefined fields are:
Host:Host, Host is unified with the host-name. If Host is of the format <host>:<port> Host only describes <host> and a field
port(Port)where Port is an integer is added.
trace). This field is present if the header has been parsed successfully.
ip(A,B,C,D)containing the IP address of the contacting host.
, normally used to transfer data from HTML forms that use the HTTP GET method. In the URL it consists of a www-form-encoded list of Name=Value pairs. This is mapped to a list of Prolog Name=Value terms with decoded names and values. This field is only present if the location contains a search-specification.
The URL specification does not demand the query part to be of the form name=value. If the field is syntactically incorrect, ListOfNameValue is bound the the empty list ().
HTTP/Major.Minor version indicator this element indicate the HTTP version of the peer. Otherwise this field is not present.
Cookieline, the value of the cookie is broken down in Name=Value pairs, where the Name is the lowercase version of the cookie name as used for the HTTP fields.
SetCookieline, the cookie field is broken down into the Name of the cookie, the Value and a list of Name=Value pairs for additional options such as
If the first line of the request is tagged with
reads all input upto the first blank line. This header consists of
Name:Value fields. Each such field appears as a
Name(Value) in the Request, where Name
is canonicalised for use with Prolog. Canonisation implies that the
Name is converted to lower case and all occurrences of the
are replaced by
_. The value
Content-length fields is translated into an integer.
Here is an example:
?- http_read_request(user_input, X). |: GET /mydb?class=person HTTP/1.0 |: Host: gollem |: X = [ input(user), method(get), search([ class = person ]), path('/mydb'), http_version(1-0), host(gollem) ].
Where the HTTP
GET operation is intended to get a
document, using a path and possibly some additional search
POST operation is intended to hand
potentially large amounts of data to the server for processing.
The Request parameter above contains the term
The data posted is left on the input stream that is available through
input(Stream) from the Request header.
This data can be read using http_read_data/3
from the HTTP client library. Here is a demo implementation simply
returning the parsed posted data as plain text (assuming pp/1
pretty-prints the data).
reply(Request) :- member(method(post), Request), !, http_read_data(Request, Data, ), format('Content-type: text/plain~n~n', ), pp(Data).
If the POST is initiated from a browser, content-type is generally