The urdl::url class gives us the ability to parse URLs and access their component parts. The default constructor:
// For urdl::url. #include <urdl/url.hpp> ... urdl::url url("http://somehost/path");
provides a conversion from std::string
or const char*
to URLs. If the URL does not parse correctly,
the constructor throws an exception of type boost::system::system_error
.
It is this constructor that is used when we write:
urdl::istream is("http://somehost/path");
We can also use the urdl::url::from_string static member function to explicitly parse a URL, with the option of choosing a throwing overload:
urdl::url url = urdl::url::from_string("http://somehost/path");
or an overload that does not throw an exception on failure:
boost::system::error_code ec; urdl::url url = urdl::url::from_string("http://somehost/path", ec);