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



On Fri, Apr 15, 2016 at 4:18 PM, Jeffrey Stedfast <fejj gnome org> wrote:


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()


Don't forget to call g_mime_stream_reset (stream);

Otherwise the parser will attempt to parse the stream starting at the very
end of the content (i.e. the parser will have nothing to parse).


BINGO! That fixed it. Never thought of that.


   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??


Yes, it will only loop once because it will return a GMimeMultipart since
that's what the content is.

The HTTP headers contain the following Content-Type header:


One last question. With resetting the stream I got it working, but I'm using
g_mime_parser_construct_message(). If that's the case, what is the
difference between
using that and g_mime_parser_construct_part() ?

Thanks,
Ron


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