[gmime-devel] Problem parsing HTTP POST multipart/form-data



Hi,

I'm having huge problems parsing multipart/form-data. I'm using 2.4.21
(because CentOS 6).

This is my POST command:

curl -v -F key1=value1 -F "key2=value2" -F "file= test txt"
http://localhost:5657/v1/test

This is the resulting HTTP request:

---------------------------------------------- start ----------------
POST /v1/test HTTP/1.1
User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7
NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Host: localhost:5657
Accept: */*
Content-Length: 432
Content-Type: multipart/form-data;
boundary=----------------------------2912a7dc5b77

------------------------------2912a7dc5b77
Content-Disposition: form-data; name="key1"

value1
------------------------------2912a7dc5b77
Content-Disposition: form-data; name="key2"

value2
------------------------------2912a7dc5b77
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

his is my testfile.
And this is another line.
------------------------------------------------- end ------------

Now, how do I parse this? On the server side I'm using libevent. My
approach was:

  stream = g_mime_stream_mem_new();

  // not shown, but write all headers to the stream using
g_mime_stream_write() each followed by a CRLF
  // add empty CRLF, and add the body using g_mime_stream_write()

  parser = g_mime_parser_new_with_stream (stream);

  // parse the block from the stream.  vdoes not exist?
  multipart = g_mime_multipart_new();
  while ((object = g_mime_parser_construct_part(parser)) != NULL) {
    g_mime_multipart_add(multipart, object);
  }
  // but this loops only once??

  Trying to loop over it using g_mime_multipart_foreach() fails, one
leaf is found, but it has no content-disposition.

This is just one of my attempts. I tried using GMimeMessage, but that
didn't work either
I'm at a loss here, I must be missing something.

Please advise.

Thanks,
Ron


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]