Search…
Get individual URL parts
When a URL has been parsed or individual parts have been set in the CURLU handle, you can extract those pieces again from the handle at any time.
The second argument to curl_url_get() specifies which part you want extracted. They are all extracted as null-terminated char * data, so you pass a pointer to such a variable.
1
char *host;
2
rc = curl_url_get(h, CURLUPART_HOST, &host, 0);
3
4
char *scheme;
5
rc = curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);
6
7
char *user;
8
rc = curl_url_get(h, CURLUPART_USER, &user, 0);
9
10
char *password;
11
rc = curl_url_get(h, CURLUPART_PASSWORD, &password, 0);
12
13
char *port;
14
rc = curl_url_get(h, CURLUPART_PORT, &port, 0);
15
16
char *path;
17
rc = curl_url_get(h, CURLUPART_PATH, &path, 0);
18
19
char *query;
20
rc = curl_url_get(h, CURLUPART_QUERY, &query, 0);
21
22
char *fragment;
23
rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);
Copied!
Remember to free the returned string with curl_free when you are done with it!
Extracted parts are not URL decoded unless the user asks for it with the CURLU_URLDECODE flag.
Export as PDF
Copy link
Edit on GitHub