![]() |
![]()
| ![]() |
![]()
NAMElibcurl-url - URL interface overview DESCRIPTIONThe URL interface provides functions for parsing and generating URLs. INCLUDEYou still only include <curl/curl.h> in your code. CREATECreate a handle that holds URL info and resources with curl_url(3):
CLEANUPWhen done with it, clean it up with curl_url_cleanup(3)
DUPLICATEWhen you need a copy of a handle, just duplicate it with curl_url_dup(3):
PARSINGBy 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.
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. REDIRECTWhen a handle already contains info about a URL, setting a relative URL makes it "redirect" to that.
GET URLThe CURLU handle represents a URL and you can easily extract that with curl_url_get(3):
The zero in the fourth argument is a bitmask for changing specific features. GET PARTSWhen a URL has been parsed or parts have been set, you can extract those pieces from the handle at any time.
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 PARTSA user set individual URL parts, either after having parsed a full URL or instead of parsing such.
Set parts are not URL encoded unless the user asks for it with the CURLU_URLENCODE flag. CURLU_APPENDQUERYAn 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:
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:
Now the URL looks like
NOTESA URL with a literal IPv6 address can be parsed even when IPv6 support is not enabled. SEE ALSOCURLOPT_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)
|