개발이야기
c - libcurl 로 쉽게 url encoding 하기. curl_easy_escape
준호씨
2019. 4. 24. 20:34
반응형
url 을 만들 때 공백(' ')은 %20 으로 바꿔준다던지 처리를 해 주어야 한다. libcurl 의 curl_easy_escape 함수를 이용하면 손쉽게 처리 할 수 있다.
#include <stdio.h>
#include <curl/curl.h>
#include <string.h>
int main() {
CURL *curl = curl_easy_init();
if (curl) {
char *string = "hello world";
printf("%lu\n", strlen(string)); // 11
char *output = curl_easy_escape(curl, string, strlen(string));
if (output) {
printf("Encoded: %s\n", output); // Encoded: hello%20world
curl_free(output);
}
}
return 0;
}
- curl_easy_escape - URL encode the given string https://curl.haxx.se/libcurl/c/curl_easy_escape.html
반응형