blob: c21dc7504a3c6611f220fdb330d0dce8f6ab3556 [file] [log] [blame]
Lucas Eckels9bd90e62012-08-06 15:07:02 -07001.\" **************************************************************************
2.\" * _ _ ____ _
3.\" * Project ___| | | | _ \| |
4.\" * / __| | | | |_) | |
5.\" * | (__| |_| | _ <| |___
6.\" * \___|\___/|_| \_\_____|
7.\" *
Elliott Hughes82be86d2017-09-20 17:00:17 -07008.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
Lucas Eckels9bd90e62012-08-06 15:07:02 -07009.\" *
10.\" * This software is licensed as described in the file COPYING, which
11.\" * you should have received as part of this distribution. The terms
Alex Deymo8f1a2142016-06-28 14:49:26 -070012.\" * are also available at https://curl.haxx.se/docs/copyright.html.
Lucas Eckels9bd90e62012-08-06 15:07:02 -070013.\" *
14.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15.\" * copies of the Software, and permit persons to whom the Software is
16.\" * furnished to do so, under the terms of the COPYING file.
17.\" *
18.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19.\" * KIND, either express or implied.
20.\" *
21.\" **************************************************************************
22.\"
Elliott Hughes1ef06ba2018-05-30 15:43:58 -070023.TH curl_easy_escape 3 "August 12, 2017" "libcurl 7.60.0" "libcurl Manual"
Elliott Hughes82be86d2017-09-20 17:00:17 -070024
Lucas Eckels9bd90e62012-08-06 15:07:02 -070025.SH NAME
26curl_easy_escape - URL encodes the given string
27.SH SYNOPSIS
28.B #include <curl/curl.h>
29.sp
Alex Deymo8f1a2142016-06-28 14:49:26 -070030.BI "char *curl_easy_escape( CURL *" curl ", const char *" string
31.BI ", int "length " );"
Lucas Eckels9bd90e62012-08-06 15:07:02 -070032.ad
33.SH DESCRIPTION
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070034This function converts the given input \fIstring\fP to a URL encoded string
35and returns that as a new allocated string. All input characters that are not
36a-z, A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped"
37version (%NN where NN is a two-digit hexadecimal number).
Lucas Eckels9bd90e62012-08-06 15:07:02 -070038
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070039If \fIlength\fP is set to 0 (zero), \fIcurl_easy_escape(3)\fP uses strlen() on
40the input \fIstring\fP to find out the size.
Lucas Eckels9bd90e62012-08-06 15:07:02 -070041
42You must \fIcurl_free(3)\fP the returned string when you're done with it.
Elliott Hughes82be86d2017-09-20 17:00:17 -070043.SH ENCODING
44libcurl is typically not aware of, nor does it care about, character
45encodings. \fIcurl_easy_escape(3)\fP encodes the data byte-by-byte into the
46URL encoded version without knowledge or care for what particular character
47encoding the application or the receiving server may assume that the data
48uses.
49
50The caller of \fIcurl_easy_escape(3)\fP must make sure that the data passed in
51to the function is encoded correctly.
Lucas Eckels9bd90e62012-08-06 15:07:02 -070052.SH AVAILABILITY
53Added in 7.15.4 and replaces the old \fIcurl_escape(3)\fP function.
54.SH RETURN VALUE
55A pointer to a zero terminated string or NULL if it failed.
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070056.SH EXAMPLE
57.nf
58CURL *curl = curl_easy_init();
59if(curl) {
60 char *output = curl_easy_escape(curl, "data to convert", 15);
61 if(output) {
Alex Deymo8f1a2142016-06-28 14:49:26 -070062 printf("Encoded: %s\\n", output);
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070063 curl_free(output);
64 }
Alex Deymo8f1a2142016-06-28 14:49:26 -070065}
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070066.fi
Lucas Eckels9bd90e62012-08-06 15:07:02 -070067.SH "SEE ALSO"
Bertrand SIMONNETe6cd7382015-07-01 15:39:44 -070068.BR curl_easy_unescape "(3), " curl_free "(3), " RFC 3986