Man page - libcurl-url(3)
Packages contas this manual
- curl_multi_socket(3)
- curl_global_trace(3)
- curl_easy_reset(3)
- curl_url_dup(3)
- curl_free(3)
- curl_easy_option_next(3)
- curl_maprintf(3)
- curl_mvprintf(3)
- curl_share_setopt(3)
- curl_strnequal(3)
- curl_escape(3)
- libcurl-multi(3)
- curl_multi_socket_all(3)
- curl_strequal(3)
- curl_easy_recv(3)
- curl_slist_append(3)
- curl_share_cleanup(3)
- curl_msnprintf(3)
- curl_easy_upkeep(3)
- curl_multi_wait(3)
- curl_mime_addpart(3)
- libcurl-env(3)
- curl_multi_waitfds(3)
- curl_ws_send(3)
- curl_multi_perform(3)
- curl_slist_free_all(3)
- curl_ws_meta(3)
- curl_multi_poll(3)
- curl_share_init(3)
- libcurl-symbols(3)
- curl_url_cleanup(3)
- libcurl-tutorial(3)
- curl_mime_free(3)
- curl_multi_timeout(3)
- curl_multi_socket_action(3)
- libcurl-easy(3)
- curl_easy_strerror(3)
- curl_easy_option_by_id(3)
- libcurl-ws(3)
- curl_mvfprintf(3)
- curl_mvsnprintf(3)
- libcurl(3)
- curl_easy_send(3)
- curl_easy_escape(3)
- curl_getenv(3)
- curl_mvsprintf(3)
- libcurl-env-dbg(3)
- curl_mime_init(3)
- libcurl-security(3)
- curl_mime_filename(3)
- curl_mime_name(3)
- curl_easy_ssls_export(3)
- curl_formget(3)
- curl_multi_init(3)
- curl_mime_data(3)
- curl_pushheader_byname(3)
- curl_mime_subparts(3)
- curl_easy_unescape(3)
- libcurl-errors(3)
- curl_easy_header(3)
- curl_global_init_mem(3)
- curl_mfprintf(3)
- libcurl-thread(3)
- curl_multi_remove_handle(3)
- curl_url_set(3)
- curl_version_info(3)
- curl_multi_cleanup(3)
- curl_formfree(3)
- curl_multi_assign(3)
- curl_url_get(3)
- curl_mime_filedata(3)
- curl_multi_fdset(3)
- curl_mime_type(3)
- libcurl-url(3)
- curl_version(3)
- curl_easy_option_by_name(3)
- curl_multi_strerror(3)
- curl_easy_nextheader(3)
- curl_unescape(3)
- curl_share_strerror(3)
- curl_mime_data_cb(3)
- curl_multi_get_handles(3)
- curl_global_sslset(3)
- curl_easy_pause(3)
- curl_easy_ssls_import(3)
- curl_multi_info_read(3)
- curl_global_cleanup(3)
- curl_multi_add_handle(3)
- curl_mprintf(3)
- curl_ws_recv(3)
- curl_mvaprintf(3)
- curl_easy_init(3)
- libcurl-share(3)
- curl_multi_setopt(3)
- curl_url_strerror(3)
- curl_easy_perform(3)
- curl_easy_cleanup(3)
- curl_easy_getinfo(3)
- curl_msprintf(3)
- curl_easy_setopt(3)
- curl_getdate(3)
- curl_mime_headers(3)
- curl_url(3)
- curl_mime_encoder(3)
- curl_multi_wakeup(3)
- curl_easy_duphandle(3)
- curl_formadd(3)
- curl_pushheader_bynum(3)
- curl_global_init(3)
apt-get install libcurl4-doc
Manual
| libcurl-url(3) | Library Functions Manual | libcurl-url(3) |
NAME
libcurl-url - URL interface overview
DESCRIPTION
The URL interface provides functions for parsing and generating URLs.
INCLUDE
You still only include <curl/curl.h> in your code.
CREATE
Create a handle that holds URL info and resources with curl_url(3):
CURLU *h = curl_url();
CLEANUP
When done with it, clean it up with curl_url_cleanup(3)
curl_url_cleanup(h);
DUPLICATE
When you need a copy of a handle, just duplicate it with curl_url_dup(3):
CURLU *nh = curl_url_dup(h);
PARSING
By setting a URL to the handle with curl_url_set(3), the URL is parsed and stored in the handle. If the URL is not syntactically correct it returns an error instead.
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.
REDIRECT
When a handle already contains info about a URL, setting a relative URL makes it "redirect" to that.
rc = curl_url_set(h, CURLUPART_URL, "../test?another", 0);
GET URL
The CURLU handle represents a URL and you can easily extract that with curl_url_get(3):
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.
GET PARTS
When a URL has been parsed or parts have been set, you can extract those pieces from the handle at any time.
rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);
rc = curl_url_get(h, CURLUPART_HOST, &host, 0);
rc = curl_url_get(h, CURLUPART_PASSWORD, &password, 0);
rc = curl_url_get(h, CURLUPART_PATH, &path, 0);
rc = curl_url_get(h, CURLUPART_PORT, &port, 0);
rc = curl_url_get(h, CURLUPART_QUERY, &query, 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_ZONEID, &zoneid, 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 are done with it.
SET PARTS
A user set individual URL parts, either after having parsed a full URL or instead of parsing such.
rc = curl_url_set(urlp, CURLUPART_FRAGMENT, "anchor", 0);
rc = curl_url_set(urlp, CURLUPART_HOST, "www.example.com", 0);
rc = curl_url_set(urlp, CURLUPART_PASSWORD, "doe", 0);
rc = curl_url_set(urlp, CURLUPART_PATH, "/index.html", 0);
rc = curl_url_set(urlp, CURLUPART_PORT, "443", 0);
rc = curl_url_set(urlp, CURLUPART_QUERY, "name=john", 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_ZONEID, "eth0", 0);
Set parts are not URL encoded unless the user asks for it with the CURLU_URLENCODE flag.
CURLU_APPENDQUERY
An application can append a string to the right end of the query part with the CURLU_APPENDQUERY flag to curl_url_set(3).
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 notices the lack of an ampersand (&) separator and injects one, and the handle's full URL then equals "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 skips 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
NOTES
A URL with a literal IPv6 address can be parsed even when IPv6 support is not enabled.
SEE ALSO
CURLOPT_URL(3), curl_url(3), curl_url_cleanup(3), curl_url_dup(3), curl_url_get(3), curl_url_set(3), curl_url_strerror(3)
| 2025-11-09 | libcurl |