Alessandro Vesely helped me improve the --data-urlencode's syntax, parser
and documentation.
This commit is contained in:
4
CHANGES
4
CHANGES
@@ -7,6 +7,10 @@
|
|||||||
Changelog
|
Changelog
|
||||||
|
|
||||||
|
|
||||||
|
Daniel S (22 Nov 2007)
|
||||||
|
- Alessandro Vesely helped me improve the --data-urlencode's syntax, parser
|
||||||
|
and documentation.
|
||||||
|
|
||||||
Daniel S (21 Nov 2007)
|
Daniel S (21 Nov 2007)
|
||||||
- While inspecting the Negotiate code, I noticed how the proxy auth was using
|
- While inspecting the Negotiate code, I noticed how the proxy auth was using
|
||||||
the same state struct as the host auth, so both could never be used at the
|
the same state struct as the host auth, so both could never be used at the
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ advice from friends like these:
|
|||||||
|
|
||||||
Dan Fandrich, Gisle Vanem, Toby Peterson, Yang Tse, Daniel Black,
|
Dan Fandrich, Gisle Vanem, Toby Peterson, Yang Tse, Daniel Black,
|
||||||
Robin Johnson, Michal Marek, Ates Goral, Andres Garcia, Rob Crittenden,
|
Robin Johnson, Michal Marek, Ates Goral, Andres Garcia, Rob Crittenden,
|
||||||
Emil Romanus
|
Emil Romanus, Alessandro Vesely
|
||||||
|
|
||||||
Thanks! (and sorry if I forgot to mention someone)
|
Thanks! (and sorry if I forgot to mention someone)
|
||||||
|
|||||||
76
docs/curl.1
76
docs/curl.1
@@ -224,56 +224,62 @@ To create remote directories when using FTP or SFTP, try
|
|||||||
If this option is used several times, the following occurrences make no
|
If this option is used several times, the following occurrences make no
|
||||||
difference.
|
difference.
|
||||||
.IP "-d/--data <data>"
|
.IP "-d/--data <data>"
|
||||||
(HTTP) Sends the specified data in a POST request to the HTTP server, in a way
|
(HTTP) Sends the specified data in a POST request to the HTTP server, in the
|
||||||
that can emulate as if a user has filled in a HTML form and pressed the submit
|
same way that a browser does when a user has filled in an HTML form and
|
||||||
button. Note that the data is sent exactly as specified with no extra
|
presses the submit button. This will cause curl to pass the data to the server
|
||||||
processing (with all newlines cut off). The data is expected to be
|
using the content-type application/x-www-form-urlencoded. Compare to
|
||||||
\&"url-encoded". This will cause curl to pass the data to the server using the
|
\fI-F/--form\fP.
|
||||||
content-type application/x-www-form-urlencoded. Compare to \fI-F/--form\fP. If
|
|
||||||
this option is used more than once on the same command line, the data pieces
|
\fI-d/--data\fP is the same as \fI--data-ascii\fP. To post data purely binary,
|
||||||
specified will be merged together with a separating &-letter. Thus, using '-d
|
you should instead use the \fI--data-binary\fP option. To URL encode the value
|
||||||
name=daniel -d skill=lousy' would generate a post chunk that looks like
|
of a form field you may use \fI--data-urlencode\fP.
|
||||||
\&'name=daniel&skill=lousy'.
|
|
||||||
|
If any of these options is used more than once on the same command line, the
|
||||||
|
data pieces specified will be merged together with a separating
|
||||||
|
&-letter. Thus, using '-d name=daniel -d skill=lousy' would generate a post
|
||||||
|
chunk that looks like \&'name=daniel&skill=lousy'.
|
||||||
|
|
||||||
If you start the data with the letter @, the rest should be a file name to
|
If you start the data with the letter @, the rest should be a file name to
|
||||||
read the data from, or - if you want curl to read the data from stdin. The
|
read the data from, or - if you want curl to read the data from stdin. The
|
||||||
contents of the file must already be url-encoded. Multiple files can also be
|
contents of the file must already be url-encoded. Multiple files can also be
|
||||||
specified. Posting data from a file named 'foobar' would thus be done with
|
specified. Posting data from a file named 'foobar' would thus be done with
|
||||||
\fI--data\fP @foobar".
|
\fI--data @foobar\fP.
|
||||||
|
|
||||||
To post data purely binary, you should instead use the \fI--data-binary\fP
|
|
||||||
option.
|
|
||||||
|
|
||||||
\fI-d/--data\fP is the same as \fI--data-ascii\fP.
|
|
||||||
|
|
||||||
If this option is used several times, the ones following the first will
|
|
||||||
append data.
|
|
||||||
.IP "--data-ascii <data>"
|
|
||||||
(HTTP) This is an alias for the \fI-d/--data\fP option.
|
|
||||||
|
|
||||||
If this option is used several times, the ones following the first will
|
|
||||||
append data.
|
|
||||||
.IP "--data-binary <data>"
|
.IP "--data-binary <data>"
|
||||||
(HTTP) This posts data in a similar manner as \fI--data-ascii\fP does,
|
(HTTP) This posts data exactly as specified with no extra processing
|
||||||
although when using this option the entire context of the posted data is kept
|
whatsoever.
|
||||||
as-is. If you want to post a binary file without the strip-newlines feature of
|
|
||||||
the \fI--data-ascii\fP option, this is for you.
|
|
||||||
|
|
||||||
If this option is used several times, the ones following the first will
|
If you start the data with the letter @, the rest should be a filename. Data
|
||||||
append data.
|
is posted in a similar manner as \fI--data-ascii\fP does, except that newlines
|
||||||
|
are preserved and conversions are never done.
|
||||||
|
|
||||||
|
If this option is used several times, the ones following the first will append
|
||||||
|
data. As described in \fI-d/--data\fP.
|
||||||
.IP "--data-urlencode <data>"
|
.IP "--data-urlencode <data>"
|
||||||
(HTTP) This posts data, similar to the other --data options with the exception
|
(HTTP) This posts data, similar to the other --data options with the exception
|
||||||
that this will do partial URL encoding. (Added in 7.17.2)
|
that this performs URL encoding. (Added in 7.17.2)
|
||||||
|
|
||||||
The <data> part should be using one of the two following syntaxes:
|
To be CGI compliant, the <data> part should begin with a \fIname\fP followed
|
||||||
|
by a separator and a content specification. The <data> part can be passed to
|
||||||
|
curl using one of the following syntaxes:
|
||||||
.RS
|
.RS
|
||||||
|
.IP "content"
|
||||||
|
This will make curl URL encode the content and pass that on. Just be careful
|
||||||
|
so that the content doesn't contain any = or @ letters, as that will then make
|
||||||
|
the syntax match one of the other cases below!
|
||||||
|
.IP "=content"
|
||||||
|
This will make curl URL encode the content and pass that on. The preceding =
|
||||||
|
letter is not included in the data.
|
||||||
.IP "name=content"
|
.IP "name=content"
|
||||||
This will make curl URL encode the content part and pass that on. Note that
|
This will make curl URL encode the content part and pass that on. Note that
|
||||||
the name part is expected to be URL encoded already.
|
the name part is expected to be URL encoded already.
|
||||||
|
.IP "@filename"
|
||||||
|
This will make curl load data from the given file (including any newlines),
|
||||||
|
URL encode that data and pass it on in the POST.
|
||||||
.IP "name@filename"
|
.IP "name@filename"
|
||||||
This will make curl load data from the given file, URL encode that data and
|
This will make curl load data from the given file (including any newlines),
|
||||||
pass it on in the POST like \fIname=urlencoded-data\fP. Note that the name
|
URL encode that data and pass it on in the POST. The name part gets an equal
|
||||||
is expected to be URL encoded already.
|
sign appended, resulting in \fIname=urlencoded-file-content\fP. Note that the
|
||||||
|
name is expected to be URL encoded already.
|
||||||
.RE
|
.RE
|
||||||
.IP "--digest"
|
.IP "--digest"
|
||||||
(HTTP) Enables HTTP Digest authentication. This is a authentication that
|
(HTTP) Enables HTTP Digest authentication. This is a authentication that
|
||||||
|
|||||||
24
src/main.c
24
src/main.c
@@ -2059,19 +2059,21 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
*/
|
*/
|
||||||
char *p = strchr(nextarg, '=');
|
char *p = strchr(nextarg, '=');
|
||||||
long size = 0;
|
long size = 0;
|
||||||
size_t nlen;
|
int nlen;
|
||||||
|
char is_file;
|
||||||
if(!p)
|
if(!p)
|
||||||
p = strchr(nextarg, '@');
|
p = strchr(nextarg, '@');
|
||||||
if(!p) {
|
if (p) {
|
||||||
warnf(config, "bad use of --data-urlencode\n");
|
|
||||||
return PARAM_BAD_USE;
|
|
||||||
}
|
|
||||||
nlen = p - nextarg; /* length of the name part */
|
nlen = p - nextarg; /* length of the name part */
|
||||||
if('@' == *p) {
|
is_file = *p++; /* pass the separator */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nlen = is_file = -1;
|
||||||
|
p = nextarg;
|
||||||
|
}
|
||||||
|
if('@' == is_file) {
|
||||||
/* a '@' letter, it means that a file name or - (stdin) follows */
|
/* a '@' letter, it means that a file name or - (stdin) follows */
|
||||||
|
|
||||||
p++; /* pass the separator */
|
|
||||||
|
|
||||||
if(curlx_strequal("-", p)) {
|
if(curlx_strequal("-", p)) {
|
||||||
file = stdin;
|
file = stdin;
|
||||||
SET_BINMODE(stdin);
|
SET_BINMODE(stdin);
|
||||||
@@ -2090,7 +2092,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GetStr(&postdata, ++p);
|
GetStr(&postdata, p);
|
||||||
size = strlen(postdata);
|
size = strlen(postdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2108,8 +2110,10 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
|
|||||||
char *n = malloc(outlen);
|
char *n = malloc(outlen);
|
||||||
if(!n)
|
if(!n)
|
||||||
return PARAM_NO_MEM;
|
return PARAM_NO_MEM;
|
||||||
|
if (nlen > 0) /* only append '=' if we have a name */
|
||||||
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
|
snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
|
||||||
|
else
|
||||||
|
strcpy(n, enc);
|
||||||
curl_free(enc);
|
curl_free(enc);
|
||||||
free(postdata);
|
free(postdata);
|
||||||
if(n) {
|
if(n) {
|
||||||
|
|||||||
Reference in New Issue
Block a user