I am trying to encode a request. The request goes as follow:
https://www.overpass-api.de/api/interpreter?data=area["name"="Nicaragua"]["admin_level"="2"]->.boundaryarea;(node["type"="route"]["route"="bus"](area.boundaryarea);way["type"="route"]["route"="bus"](area.boundaryarea);>;relation["type"="route"]["route"="bus"](area.boundaryarea);>>;);out meta;
As you can see, you have a lot of special characters. If I give this URL to curl, I won't process it because of some characters. Hence I decided to encode the URL with my own method and with curl's method. Here is the code sample to encode with curl:
std::string d = ...;
CURL *curl = curl_easy_init();
if(curl) {
char *output = curl_easy_escape(curl, d.c_str(), d.length());
if(output) {
printf("Encoded: %s\n", output);
curl_free(output);
}
}
Will encode the whole request resulting in something like
https%3A%2F%2Fwww.overpass-api.de%2Fapi%2Finterpreter%3Fdata%3D ...
If I then try to give it to curl to process it, it will throw and say that it cannot resolve the host, which makes sense to me. So I then decided to check what chrome does when encoding it - thanks to the dev tools. And this is how it looks like:
https://www.overpass-api.de/api/interpreter?data=area[%22name%22=%22Nicaragua%22][%22admin_level%22=%222%22]-%3E.boundaryarea;(node[%22type%22=%22route%22][%22route%22=%22bus%22](area.boundaryarea);way[%22type%22=%22route%22][%22route%22=%22bus%22](area.boundaryarea);%3E;relation[%22type%22=%22route%22][%22route%22=%22bus%22](area.boundaryarea);%3E%3E;);out%20meta;
And if I give this to curl as it is - it will process it properly.
Why some characters are encoded and not the rest? and why does curl accept it this way ?
EDIT: and more importantly, how can I replicate that in my code?