rc = curl_url_set(h, CURLUPART_URL, "https://example.com:449/foo/bar?name=moo", 0);
The zero in the fourth argument is a bitmask for changing specific features.
If successful, this stores the URL in its individual parts within the handle.
rc = curl_url_set(h, CURLUPART_URL, "../test?another", 0);
char *url;
rc = curl_url_get(h, CURLUPART_URL, &url, 0);
curl_free(url);
The zero in the fourth argument is a bitmask for changing specific features.
rc = curl_url_get(h, CURLUPART_HOST, &host, 0); rc = curl_url_get(h, CURLUPART_SCHEME, &scheme, 0); rc = curl_url_get(h, CURLUPART_USER, &user, 0); rc = curl_url_get(h, CURLUPART_PASSWORD, &password, 0); rc = curl_url_get(h, CURLUPART_PORT, &port, 0); rc = curl_url_get(h, CURLUPART_PATH, &path, 0); rc = curl_url_get(h, CURLUPART_QUERY, &query, 0); rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);
Extracted parts are not URL decoded unless the user also asks for it with the CURLU_URLDECODE flag set in the fourth bitmask argument.
Remember to free the returned string with curl_free(3) when you're done with it!
rc = curl_url_set(urlp, CURLUPART_HOST, "www.example.com", 0); rc = curl_url_set(urlp, CURLUPART_SCHEME, "https", 0); rc = curl_url_set(urlp, CURLUPART_USER, "john", 0); rc = curl_url_set(urlp, CURLUPART_PASSWORD, "doe", 0); rc = curl_url_set(urlp, CURLUPART_PORT, "443", 0); rc = curl_url_set(urlp, CURLUPART_PATH, "/index.html", 0); rc = curl_url_set(urlp, CURLUPART_QUERY, "name=john", 0); rc = curl_url_set(urlp, CURLUPART_FRAGMENT, "anchor", 0);
Set parts are not URL encoded unless the user asks for it with the `CURLU_URLENCODE` flag.
Imagine a handle that holds the URL `https://example.com/?shoes=2`. An application can then add the string `hat=1` to the query part like this:
rc = curl_url_set(urlp, CURLUPART_QUERY, "hat=1", CURLU_APPENDQUERY);
It will even notice the lack of an ampersand (`&`) separator so it will inject one too, and the handle's full URL will then equal `https://example.com/?shoes=2&hat=1`.
The appended string can of course also get URL encoded on add, and if asked to URL encode, the encoding process will skip the '=' character. For example, append `candy=N&N` to what we already have, and URL encode it to deal with the ampersand in the data:
rc = curl_url_set(urlp, CURLUPART_QUERY, "candy=N&N", CURLU_APPENDQUERY | CURLU_URLENCODE);
Now the URL looks like
https://example.com/?shoes=2&hat=1&candy=N%26N`