Re: How do you post multipart/form-data?

>>>>> Norbert Piega <npiega@SeeBeyond.com>:

> Anybody out there with sample code for
> posting multipart/form-data using libwww?  

I don't have any code in a usable shareable form.  Basically you have
to build a multipart/form-data request yourself.  I build it into a
char* buffer.  Some things to be aware of:
 1. all part header lines and boundary lines must be CRLF separated
 2. the boundary between the parts starts with two "-" characters, 
    the rest of the boundary, is what's given as the "boundary"
    parameter to the multipart/form-data MIME type
 3. the terminating boundary has two extra "-" characters trailing it

If "char* data" is a buffer holding the part set up above, and "char*
boundary" is a text variable holding the boundary (except for the
stuff added in 2 and 3), and "char* url" is the address you're POSTing
to, the code for setting up the request, is something like this (NB!
not tested as runnable code):
    ...
    HTParentAnchor* src = HTTmpAnchor(NULL);
    HTAnchor_setDocument(src,data);
    HTAnchor_setLength(src,strlen(data));
    HTRequest* request = HTRequest_new();
    HTAnchor_setFormat(src,HTAtom_for("multipart/form-data"));
    HTAnchor_addFormatParam(src,"boundary",boundary);
    HTAnchor* dest = HTAnchor_findAddress(url);
    int status = HTPutAnchor(src,dest,request);
    ...

Some references:
 [1] RFC2388, the definition of the multipart/form-data MIME type
	<http://www.ietf.org/rfc/rfc2388.txt>
 [2] RFC2046, section 5 describes multiparts, and the syntax of
     multipart boundaries
	<http://www.ietf.org/rfc/rfc2046.txt>

Received on Sunday, 10 December 2000 14:28:20 UTC