Created
December 16, 2015 14:01
-
-
Save tuxmartin/c572d44d40a87002265b to your computer and use it in GitHub Desktop.
C++ POCO URI parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// g++ -o poco_uri_parser poco_uri_parser.cpp -L/usr/local/lib -lPocoNet -lPocoFoundation | |
// http://pocoproject.org/slides/160-URIandUUID.pdf | |
#include "Poco/URI.h" | |
#include <iostream> | |
using namespace std; | |
int main(int argc, char** argv) | |
{ | |
string uri = "http://www.example.net:8080/hello-world?num=123&str=Abc#id-1"; | |
Poco::URI uri1(uri); | |
string scheme(uri1.getScheme()); | |
string auth(uri1.getAuthority()); | |
string host(uri1.getHost()); | |
unsigned short port = uri1.getPort(); | |
string path(uri1.getPath()); | |
string query(uri1.getQuery()); | |
string frag(uri1.getFragment()); | |
string pathEtc(uri1.getPathEtc()); | |
cout << "URI= " << uri << endl; | |
cout << "scheme= " << scheme << endl; | |
cout << "auth= " << auth << endl; | |
cout << "host= " << host << endl; | |
cout << "port= " << port << endl; | |
cout << "path= " << path << endl; | |
cout << "query= " << query << endl; | |
cout << "frag= " << frag << endl; | |
cout << "pathEtc= " << pathEtc << endl; | |
/* | |
URI= http://www.example.net:8080/hello-world?num=123&str=Abc#id-1 | |
scheme= http | |
auth= www.example.net:8080 | |
host= www.example.net | |
port= 8080 | |
path= /hello-world | |
query= num=123&str=Abc | |
frag= id-1 | |
pathEtc= /hello-world?num=123&str=Abc#id-1 | |
*/ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment