Changelog
Daniel (10 September 2004)
+- As found out by Jonas Forsman, curl didn't allow -F to set Content-Type on
+ text-parts. Starting now, we can do -F "name=daniel;type=text/extra". Added
+ test case 186 to verify.
+
- Bug report #1025986. When following a Location: with a custom Host: header
replacement, curl only replaced the Host: header on the initial request
and didn't replace it on the following ones. This resulted in requests with
This release includes the following bugfixes:
+ o -F can now add Content-Type on non-file sections
o double Host: header when following Location: with replaced Host: fixed
o curl_multi_add_handle() return code fix
o "Proxy-Connection: close" is now understood and properly dealt with
If this option is used twice, the second will again disable silent failure.
.IP "-F/--form <name=content>"
(HTTP) This lets curl emulate a filled in form in which a user has pressed the
-submit button. This causes curl to POST data using the content-type
+submit button. This causes curl to POST data using the Content-Type
multipart/form-data according to RFC1867. This enables uploading of binary
files etc. To force the 'content' part to be be a file, prefix the file name
with an @ sign. To just get the content part from a file, prefix the file name
To read the file's content from stdin insted of a file, use - where the file
name should've been. This goes for both @ and < constructs.
-You can also tell curl what Content-Type to use for the file upload part, by
-using 'type=', in a manner similar to:
+You can also tell curl what Content-Type to use by using 'type=', in a manner
+similar to:
\fBcurl\fP -F "web=@index.html;type=text/html" url.com
+or
+
+\fBcurl\fP -F "name=daniel;type=text/foo" url.com
+
See further examples and details in the MANUAL.
This option can be used multiple times.
}
}
else {
+ struct curl_forms info[4];
+ int i = 0;
+ char *ct = strstr(contp, ";type=");
+
+ info[i].option = CURLFORM_COPYNAME;
+ info[i].value = name;
+ i++;
+
+ if(ct) {
+ info[i].option = CURLFORM_CONTENTTYPE;
+ info[i].value = &ct[6];
+ i++;
+ ct[0]=0; /* zero terminate here */
+ }
+
if( contp[0]=='<' ) {
+ info[i].option = CURLFORM_FILECONTENT;
+ info[i].value = contp+1;
+ i++;
+ info[i].option = CURLFORM_END;
+
if (curl_formadd(httppost, last_post,
- CURLFORM_COPYNAME, name,
- CURLFORM_FILECONTENT, contp+1, CURLFORM_END) != 0) {
- fprintf(stderr, "curl_formadd failed!\n");
+ CURLFORM_ARRAY, info, CURLFORM_END ) != 0) {
+ fprintf(stderr, "curl_formadd failed, possibly the file %s is bad!\n",
+ contp+1);
free(contents);
return 6;
}
}
else {
+ info[i].option = CURLFORM_COPYCONTENTS;
+ info[i].value = contp;
+ i++;
+ info[i].option = CURLFORM_END;
if (curl_formadd(httppost, last_post,
- CURLFORM_COPYNAME, name,
- CURLFORM_COPYCONTENTS, contp, CURLFORM_END) != 0) {
+ CURLFORM_ARRAY, info, CURLFORM_END) != 0) {
fprintf(stderr, "curl_formadd failed!\n");
free(contents);
return 7;
test512 test165 test166 test167 test168 test169 test170 test171 \
test172 test204 test205 test173 test174 test175 test176 test177 \
test513 test514 test178 test179 test180 test181 test182 test183 \
- test184 test185
+ test184 test185 test186
# The following tests have been removed from the dist since they no longer
# work. We need to fix the test suite's FTPS server first, then bring them
--- /dev/null
+# Server-side
+<reply>
+<data>
+HTTP/1.1 200 OK swsclose
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+
+blablabla
+
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+ <name>
+HTTP RFC1867-type formposting with types on text fields
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/we/want/186 -F "name=daniel;type=moo/foo" -F "html= <body>hello</body>;type=text/html"
+</command>
+# We create this file before the command is invoked!
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^(User-Agent:|Content-Type: multipart/form-data;|------------).*
+</strip>
+<protocol>
+POST /we/want/186 HTTP/1.1\r
+User-Agent: curl/7.12.2-CVS (i686-pc-linux-gnu) libcurl/7.12.2-CVS OpenSSL/0.9.7d zlib/1.2.1.1 c-ares/1.2.0 libidn/0.5.2\r
+Host: 127.0.0.1:%HTTPPORT\r
+Pragma: no-cache\r
+Accept: */*\r
+Content-Length: 305\r
+Expect: 100-continue\r
+Content-Type: multipart/form-data; boundary=----------------------------212d9006ceb5\r
+\r
+------------------------------212d9006ceb5\r
+Content-Disposition: form-data; name="name"\r
+Content-Type: moo/foo\r
+\r
+daniel\r
+------------------------------212d9006ceb5\r
+Content-Disposition: form-data; name="html"\r
+Content-Type: text/html\r
+\r
+ <body>hello</body>\r
+------------------------------212d9006ceb5--\r
+</protocol>
+</verify>