| Did you know ... | Search Documentation: |
| Predicate http_open/3 |
:- use_module(library(http/http_open)).
[det]http_open(+URL,
-Stream, +Options)false (default true), do not try to
automatically authenticate the client if a 401 (Unauthorized) status
code is received.library(http/http_digest)
is also loaded.curl(1)’s
option‘--unix-socket`.Connection header. Default is close.
The alternative is Keep-alive. This maintains a pool of
available connections as determined by keep_connection/1.
The library(http/websockets) uses Keep-alive, Upgrade.
Keep-alive connections can be closed explicitly using
http_close_keep_alive/1.
Keep-alive connections may significantly improve repetitive requests on
the same server, especially if the IP route is long, HTTPS is used or
the connection uses a proxy.header(Name,Value) option. A
pseudo header status_code(Code) is added to provide the
HTTP status as an integer. See also raw_headers(-List)
which provides the entire HTTP reply header in unparsed representation.get (default), head, delete, post, put
or
patch. The head message can be used in
combination with the header(Name, Value) option to access
information on the resource without actually fetching the resource
itself. The returned stream must be closed immediately.
If post(Data) is provided, the default is post.
Content-Length
in the reply header.Major-Minor, where Major
and Minor are integers representing the HTTP version in the
reply header.end. HTTP 1.1 only supports Unit = bytes.
E.g., to ask for bytes 1000-1999, use the option
range(bytes(1000,1999))raw_encoding('applocation/gzip') the system will not
decompress the stream if it is compressed using gzip.headers(-List).false (default true), do not
automatically redirect if a 3XX code is received. Must be combined with
status_code(Code) and one of the header options to read the
redirect reply. In particular, without status_code(Code) a
redirect is mapped to an exception.infinite).POST request on the HTTP server. Data is
handed to http_post_data/3.proxy(+Host:Port). Deprecated.authorization option.true, bypass proxy hooks. Default is false.infinite.
The default value is 10.User-Agent field of the HTTP
header. Default is SWI-Prolog.
The hook http:open_options/2
can be used to provide default options based on the broken-down URL.
The option
status_code(-Code) is particularly useful to query REST
interfaces that commonly return status codes other than 200
that need to be be processed by the client code.
| URL | is either an atom or string (url) or a
list of parts.
When provided, this list may contain the fields
http_open([ host('www.example.com'),
path('/my/path'),
search([ q='Hello world',
lang=en
])
])
|
error(existence_error(url, Id),Context) is raised if the
HTTP result code is not in the range 200..299. Context has the shape context(Message, status(Code, TextCode)),
where Code is the numeric HTTP code and TextCode
is the textual description thereof provided by the server. Message
may provide additional details or may be unbound.library(http/http_ssl_plugin) is loaded.Two examples in which the URI is specified as a list of components, both denoting the URI `https://www.example.com/?animal=monkey`:
?- http_open([host('example.com'),scheme(https),search([animal=monkey])], Stream, []).
?- http_open([host('example.com'),query_string('animal=monkey'),scheme(https)], Stream, []).