curl-users
posting data with first url only
Date: Thu, 19 Feb 2004 09:52:02 -0800 (PST)
I'm submitting patches to add an option to have -d data applied only
to the first url, and to use GET for subsequent urls. I seemed to need
this to handle a site which has a nonstandard login requirement.
diff -u -r curl-7.11.0/docs/curl.1 curl.new/docs/curl.1
--- curl-7.11.0/docs/curl.1 2003-12-18 08:16:19.000000000 -0800
+++ curl.new/docs/curl.1 2004-02-18 17:13:52.000000000 -0800
@@ -197,6 +197,12 @@
If this option is used several times, the ones following the first will
append data.
+
+.IP "--data-once"
+(HTTP) This causes all data specified by \fI-d/--data\fP or \fI--data-binary\fP
+to be sent only with the first URL, and causes curl to use GET for subsequent
+URLs. It can be useful for handling login forms.
+
.IP "--digest"
(HTTP) Enables HTTP Digest authentication. This is a authentication that
prevents the password from being sent over the wire in clear text. Use this in
diff -u -r curl-7.11.0/src/main.c curl.new/src/main.c
--- curl-7.11.0/src/main.c 2004-01-19 14:15:59.000000000 -0800
+++ curl.new/src/main.c 2004-02-17 17:23:58.000000000 -0800
@@ -395,6 +395,7 @@
off_t resume_from;
char *postfields;
long postfieldsize;
+ bool post_data_once;
char *referer;
long timeout;
long connecttimeout;
@@ -1132,6 +1133,7 @@
{"d", "data", TRUE},
{"da", "data-ascii", TRUE},
{"db", "data-binary", TRUE},
+ {"d1", "data-once", FALSE},
{"D", "dump-header", TRUE},
{"e", "referer", TRUE},
{"E", "cert", TRUE},
@@ -1512,6 +1514,10 @@
{
char *postdata=NULL;
+ if(subletter == '1') {
+ config->post_data_once = TRUE;
+ break;
+ }
if('@' == *nextarg) {
/* the data begins with a '@' letter, it means that a file name
or - (stdin) follows */
@@ -3339,6 +3345,17 @@
if (httpgetfields)
free(httpgetfields);
+ if (config->post_data_once && config->postfields != NULL) {
+ httpgetfields = NULL;
+ config->httpreq = HTTPREQ_UNSPEC;
+ config->httppost = NULL;
+ free(config->postfields);
+ config->postfields = NULL;
+ if(SetHTTPrequest((config->conf&CONF_NOBODY?HTTPREQ_HEAD:HTTPREQ_GET),
+ &config->httpreq))
+ return PARAM_BAD_USE;
+ curl_easy_setopt(curl, CURLOPT_POST, NULL);
+ }
if(url)
free(url);
-- ------------------------------------------------------------------------------ Peter McCluskey | "To announce that there must be no criticism of http://www.rahul.net/pcm | the President, or that we are to stand by the | President right or wrong, is not only unpatriotic | and servile, but morally treasonable to the | American public." - Theodore RooseveltReceived on 2004-02-19