-
Notifications
You must be signed in to change notification settings - Fork 74
URI
Glyn Matthews edited this page Jun 13, 2013
·
2 revisions
Below is listed a simple code example that takes a string as an argument and prints out the different URI parts:
#include <network/uri.hpp>
#include <iostream>
int main(int argc, char *arv[]) {
network::uri uri("http://github.com/cpp-netlib/uri");
std::cout << "Scheme: " << *uri.scheme() << std::endl
<< "Authority: " << *uri.authority() << std::endl
<< "Path: " << *uri.path() << std::endl;
return 0;
}
The output of this program is:
Scheme: http Authority: github.com Path: /cpp-netlib/uri
The URI in the example above is broken into three parts according to `RFC 3986`_, the other parts aren't present. HTTP URIs are considered hierarchical, and therefore define an authority.
The second example is similar to the one above but parses an *opaque" URI, in this instance an XMPP JID:
#include <network/uri.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
network::uri uri("xmpp:[email protected]?message;subject=Hello%20World");
std::cout << "Scheme: " << *uri.scheme() << std::endl
<< "Path: " << *uri.path() << std::endl
<< "Query: " << *uri.query() << std::endl;
return 0;
}
The example above gives the following output:
Scheme: xmpp Path: [email protected] Query: message;subject=Hello%20World