16 Date: Thu, 29 Jul 2008 14:49:00 GMT
17 Server: test-server/fake
30 --libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder
36 http://%HOSTIP:%HTTPPORT/we/want/1404 -F name=value -F 'file=@log/test1404.txt,log/test1404.txt;type=magic/content;encoder=8bit,log/test1404.txt;headers=X-testheader-1: header 1;headers=X-testheader-2: header 2' --libcurl log/test1404.c
38 # We create this file before the command is invoked!
39 <file name="log/test1404.txt">
44 # Verify data after the test has been "shot"
47 (^User-Agent:.*|-----+\w+)
50 POST /we/want/1404 HTTP/1.1
51 User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.7a ipv6 zlib/1.1.4
52 Host: %HOSTIP:%HTTPPORT
55 Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
57 ------------------------------9ef8d6205763
58 Content-Disposition: form-data; name="name"
61 ------------------------------9ef8d6205763
62 Content-Disposition: form-data; name="file"
63 Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
65 Content-Disposition: attachment; filename="test1404.txt"
66 Content-Type: text/plain
70 ------------------------------9ef8d6205763
71 Content-Disposition: attachment; filename="test1404.txt"
72 Content-Type: magic/content
73 Content-Transfer-Encoding: 8bit
77 ------------------------------9ef8d6205763
78 Content-Disposition: attachment; filename="test1404.txt"
79 Content-Type: text/plain
80 X-testheader-1: header 1
81 X-testheader-2: header 2
85 ------------------------------aaaaaaaaaaaa--
87 ------------------------------9ef8d6205763--
90 # curl's default user-agent varies with version, libraries etc.
91 s/(USERAGENT, \")[^\"]+/${1}stripped/
92 # CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
93 # configurations - just ignore them
94 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
95 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
96 $_ = '' if /CURLOPT_HTTP_VERSION/
98 <file name="log/test1404.c" mode="text">
99 /********* Sample code generated by the curl command line tool **********
100 * All curl_easy_setopt() options are documented at:
101 * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
102 ************************************************************************/
103 #include <curl/curl.h>
105 int main(int argc, char *argv[])
110 curl_mimepart *part1;
112 curl_mimepart *part2;
113 struct curl_slist *slist1;
118 slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
119 slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
121 hnd = curl_easy_init();
122 curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
123 curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404");
124 curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
125 mime1 = curl_mime_init(hnd);
126 part1 = curl_mime_addpart(mime1);
127 curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
128 curl_mime_name(part1, "name");
129 part1 = curl_mime_addpart(mime1);
130 mime2 = curl_mime_init(hnd);
131 part2 = curl_mime_addpart(mime2);
132 curl_mime_filedata(part2, "log/test1404.txt");
133 part2 = curl_mime_addpart(mime2);
134 curl_mime_filedata(part2, "log/test1404.txt");
135 curl_mime_encoder(part2, "8bit");
136 curl_mime_type(part2, "magic/content");
137 part2 = curl_mime_addpart(mime2);
138 curl_mime_filedata(part2, "log/test1404.txt");
139 curl_mime_headers(part2, slist1, 1);
141 curl_mime_subparts(part1, mime2);
143 curl_mime_name(part1, "file");
144 curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
145 curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
146 curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
147 curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
148 curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
150 /* Here is a list of options the curl code used that cannot get generated
151 as source easily. You may select to either not use them or implement
154 CURLOPT_WRITEDATA set to a objectpointer
155 CURLOPT_INTERLEAVEDATA set to a objectpointer
156 CURLOPT_WRITEFUNCTION set to a functionpointer
157 CURLOPT_READDATA set to a objectpointer
158 CURLOPT_READFUNCTION set to a functionpointer
159 CURLOPT_SEEKDATA set to a objectpointer
160 CURLOPT_SEEKFUNCTION set to a functionpointer
161 CURLOPT_ERRORBUFFER set to a objectpointer
162 CURLOPT_STDERR set to a objectpointer
163 CURLOPT_DEBUGFUNCTION set to a functionpointer
164 CURLOPT_DEBUGDATA set to a objectpointer
165 CURLOPT_HEADERFUNCTION set to a functionpointer
166 CURLOPT_HEADERDATA set to a objectpointer
170 ret = curl_easy_perform(hnd);
172 curl_easy_cleanup(hnd);
174 curl_mime_free(mime1);
176 curl_mime_free(mime2);
178 curl_slist_free_all(slist1);
183 /**** End of sample code ****/