curl_easy_escape.3 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .\" generated by cd2nroff 0.1 from curl_easy_escape.md
  2. .TH curl_easy_escape 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_easy_escape \- URL encode a string
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. char *curl_easy_escape(CURL *curl, const char *string, int length);
  9. .fi
  10. .SH DESCRIPTION
  11. This function converts the given input \fIstring\fP to a URL encoded string and
  12. returns that as a new allocated string. All input characters that are not a\-z,
  13. A\-Z, 0\-9, \(aq\-\(aq, \(aq.\(aq, \(aq_\(aq or \(aq~\(aq are converted to their "URL escaped" version
  14. (\fB%NN\fP where \fBNN\fP is a two\-digit hexadecimal number).
  15. If \fIlength\fP is set to 0 (zero), \fIcurl_easy_escape(3)\fP uses strlen() on the input
  16. \fIstring\fP to find out the size. This function does not accept input strings
  17. longer than \fBCURL_MAX_INPUT_LENGTH\fP (8 MB).
  18. You must \fIcurl_free(3)\fP the returned string when you are done with it.
  19. .SH ENCODING
  20. libcurl is typically not aware of, nor does it care about, character
  21. encodings. \fIcurl_easy_escape(3)\fP encodes the data byte\-by\-byte into the
  22. URL encoded version without knowledge or care for what particular character
  23. encoding the application or the receiving server may assume that the data
  24. uses.
  25. The caller of \fIcurl_easy_escape(3)\fP must make sure that the data passed in
  26. to the function is encoded correctly.
  27. .SH URLs
  28. URLs are by definition \fIURL encoded\fP. To create a proper URL from a set of
  29. components that may not be URL encoded already, you cannot just URL encode the
  30. entire URL string with \fIcurl_easy_escape(3)\fP, because it then also converts
  31. colons, slashes and other symbols that you probably want untouched.
  32. To create a proper URL from strings that are not already URL encoded, we
  33. recommend using libcurl\(aqs URL API: set the pieces with \fIcurl_url_set(3)\fP and get
  34. the final correct URL with \fIcurl_url_get(3)\fP.
  35. .SH PROTOCOLS
  36. This functionality affects all supported protocols
  37. .SH EXAMPLE
  38. .nf
  39. int main(void)
  40. {
  41. CURL *curl = curl_easy_init();
  42. if(curl) {
  43. char *output = curl_easy_escape(curl, "data to convert", 15);
  44. if(output) {
  45. printf("Encoded: %s\\n", output);
  46. curl_free(output);
  47. }
  48. curl_easy_cleanup(curl);
  49. }
  50. }
  51. .fi
  52. .SH HISTORY
  53. Since 7.82.0, the \fBcurl\fP parameter is ignored. Prior to that there was
  54. per\-handle character conversion support for some old operating systems such as
  55. TPF, but it was otherwise ignored.
  56. .SH AVAILABILITY
  57. Added in curl 7.15.4
  58. .SH RETURN VALUE
  59. A pointer to a null\-terminated string or NULL if it failed.
  60. .SH SEE ALSO
  61. .BR curl_easy_unescape (3),
  62. .BR curl_url_get (3),
  63. .BR curl_url_set (3)