cURL / Mailing Lists / curl-library / Single Mail

curl-library

Question about Content-type: multipart

From: Waitman Gobble <gobble.wa_at_gmail.com>
Date: Sun, 6 Mar 2016 22:15:52 -0800

When I set Content-Type header to multipart/form-data and add data to
CURLOPT_POSTFIELDS it seems to hang. I thought maybe proxy issue but
tried with/without.
1) If sending simple string like a=foo&j=boo then there isn't an issue
2) If I don't set Content-Length then it doesn't hang, makes the post.
However receiving side doesn't get data (content length 172 but should
be 134610

Thanks for any help or pointers.

system,

FreeBSD ob4.cloudqx.com 10.2-RELEASE-p9 FreeBSD 10.2-RELEASE-p9 #0:

curl-7.47.0 from ports

#include <iostream>
#include <fstream>
#include <string>
#include <curl/curl.h>

using namespace std;

int main(void) {

CURL *conn = NULL;
curl_global_init(CURL_GLOBAL_DEFAULT);

conn = curl_easy_init();
static char errorBuffer[CURL_ERROR_SIZE];

curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, errorBuffer);
//curl_easy_setopt(conn, CURLOPT_URL, "http://wp.amodaco.com/filepost.php");
curl_easy_setopt(conn, CURLOPT_HEADER, 1L);
//curl_easy_setopt(conn, CURLOPT_PROXY, "http://127.0.0.1");
//curl_easy_setopt(conn, CURLOPT_PROXYPORT, 3128);

curl_easy_setopt(conn, CURLOPT_URL, "https://hub.zilla.tech/filepost.php");

char* post_string;
int post_size;
ifstream file;
file.open("/c/nginx/0/11/0000000110",ios_base::binary);
//file.open("/c/nginx/7/10/0000000107",ios_base::binary);
file.seekg(0,ios::end);
post_size = file.tellg();
file.seekg(0,ios::beg);
post_string = new char[post_size];
file.read(post_string,post_size);
file.close();

struct curl_slist *chunk = NULL;
chunk = curl_slist_append(chunk, "Content-Type: multipart/form-data;
boundary=-----------------------------84927149120355803091994092429");
std::string cl = "Content-Length: " + std::to_string(post_size);
chunk = curl_slist_append(chunk, cl.c_str());
curl_easy_setopt(conn, CURLOPT_POSTFIELDS, post_string);
curl_easy_setopt(conn, CURLOPT_HTTPHEADER, chunk);
cout << "before perform\r\n";
curl_easy_perform(conn);
curl_easy_cleanup(conn);
cout << "finis\r\n";
cout << cl << "\r\n";

return(0);
}

# c++ testcurl.cpp -I/usr/local/include -I/usr/include
-L/usr/local/lib -lcurl -o testcurl
# ./testcurl
before perform

data file:

/c/nginx/0/11/0000000110

-----------------------------84927149120355803091994092429
Content-Disposition: form-data; name="fileToUpload"; filename="Capture.PNG"
Content-Type: image/png

<89>PNG
^Z
^@^@^@^MIHDR^@^@^D<9D>^@^@^C^F^@^@^@<8A><95>^Q<F9>^@^@^@^AsRGB^@<AE><CE>^\<E9>^@^@^@^DgAMA^@^@<B1><8F>^K<FC>a^E^@^@^@
  pHYs^@^@^N<C3>^@^@^N<C3>^A
<C7>o<A8>d^@^@<FF><A5>IDATx^<EC><BD>/<AC>^]G<D6><AF><FD><F2><D1>H!&&c^V<99>E<BA>|t<A1><C9>H<91><A1>^U^Pt<B1>#<C3><90>K^B#<87>^^V`^YZ<91>.1^\^M<BE>`X4<CC>CBLF^Z<BD>8<DF><F7><E
.... etc, binary data.

-- 
Waitman Gobble
Los Altos California USA
650-900-8557
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:  https://curl.haxx.se/mail/etiquette.html
Received on 2016-03-07