Skip to content

Commit

Permalink
libcurl/url/set-part.md: show how to update a URL part
Browse files Browse the repository at this point in the history
Closes curl#253
  • Loading branch information
bagder committed Sep 16, 2022
1 parent a1b9778 commit 0abed60
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions libcurl/url/set-part.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,37 @@ provided as a string this way.

Set parts are not URL encoded unless the user asks for it with the
`CURLU_URLENCODE` flag in the forth argument.

## Update parts

By setting an individual part, you can for example first set a full URL, then
update a single component of that URL and then extract the updated version of
that URL.

For example, let's say we have this URL

const char *url="http://joe:7Hbz@example.com:8080/images?id=5445#footer";

and we want change the host in that URL to instead become `example.net`, it
could be done like this:

CURLU *h = curl_url();
rc = curl_url_set(h, CURLUPART_URL, url, 0);

Then change the host name part:

rc = curl_url_set(h, CURLUPART_HOST, "example.net", 0);

and this then now holds this URL:

http://joe:7Hbz@example.net:8080/images?id=5445#footer

If you then continue and change the path part to `/foo` like this:

rc = curl_url_set(h, CURLUPART_PATH, "/foo", 0);

and the URL handle now holds this URL:

http://joe:7Hbz@example.net:8080/foo?id=5445#footer

etc...

0 comments on commit 0abed60

Please sign in to comment.