Created
November 21, 2023 19:20
-
-
Save lemire/7a64fa2732e5e35f65568a0f98a9db18 to your computer and use it in GitHub Desktop.
C program to test curl URL normalization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc test.c -lcurl -o testcurl && ./testcurl | |
#include <curl/curl.h> | |
#include <stdio.h> | |
int main() { | |
CURLU *url = curl_url(); | |
CURLUcode rc = curl_url_set( | |
url, CURLUPART_URL, "https://www.7‑Eleven.com/Home/Privacy/Montréal", 0); | |
// Returns a CURLUcode error value, which is (0) if everything went fine. | |
if (rc == 0) { | |
char *buffer; | |
// When asked to return the full URL, curl_url_get will return a | |
// normalized and possibly cleaned up version of what was previously | |
// parsed. | |
rc = curl_url_get(url, CURLUPART_URL, &buffer, 0); | |
printf("%s\n", buffer); | |
if (rc == 0) { | |
curl_free(buffer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment