x::http::useragent::base::response resp=ua->request(x::http::GET, "https://localhost"); std::cout << resp->message.get_satus_code() << " " << resp->message.get_reason_phrase() << std::endl; for (auto hdr: resp->message) { std::cout << hdr.first << "=" << hdr.second.value() << std::endl; } if (resp->has_content()) { std::copy(resp->begin(), resp->end(), std::ostreambuf_iterator<char>(std::cout.rdbuf())); std::cout << std::flush; }
request
() returns
response to an HTTP request. Note that certain
fatal errors, like a failure to connect to the requested server, result
in a thrown exception, rather than a response
object.
x::http::useragent::base::response
is a reference to a
reference-counted object that contains the
following:
The uri
class member gives the
URI of the returned response. This is usually
the same as the request's URI, but it may
be different in several situations:
The server address in the
uri
uses
ASCII compatible encoding for international domain names.
Redirection: the user agent object
automatically handles redirects, with the
uri
showing the redirected
URI
The message
class member is a
x::http::responseimpl
class instance with the headers of the
response, a get_status_code
()
that returns the
numerical three digit HTTP status code, and a
get_reason_phrase
(), that returns the brief
HTTP status response.
x::http::responseimpl
is a subclass
x::headersbase
that holds the headers in the received response. The headers can be
iterated over.
has_content
() returns an indication whether the
response contains any content. The content of the
HTTP response is fetched by
begin
() and end
(). They
return x::http::useragent::base::body_iterator
s
that define an input sequence for the content.
begin
() and end
() can
be called exactly once. The iterators read directly from the
connection with the HTTP server. If the iterators
go out of scope before the entire contents are read, the
remainder gets read, and discarded, in the destructors.
In either case, these iterators read directly from the connection with the server. This may encounter delays, and thrown exceptions, in the event of connection-related issues.
A 401 or a 407 response from the server initializes the
challenges
container with the server's parsed
authentication challenge.