Urdl C++ Library

PrevUpHomeNext

Grouping and reusing options

Options may be grouped using an urdl::option_set object. This allows the options to be reused across multiple requests.

// For urdl::option_set.
#include <urdl/option_set.hpp>

...

urdl::option_set common_options;

// Prevent HTTP redirections.
common_options.set_option(urdl::http::max_redirects(0));

// Tell the web server about Urdl.
common_options.set_option(urdl::http::user_agent("Urdl"));

// Open a URL using only the common options.
urdl::istream is1("http://somehost/path1", common_options);

// Open a URL with additional options. In this case, the common options are
// applied to the stream as if we had called set_option invidiually for each
// option in the set.
urdl::istream is2;
is2.set_option(urdl::http::request_method("POST"));
is2.set_option(urdl::http::request_content_type("text/plain"));
is2.set_option(urdl::http::request_content("Hello, world!"));
is2.set_options(common_options);

PrevUpHomeNext