W3C home > Mailing lists > Public > www-lib@w3.org > October to December 2000

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

From: Steinar Bang <sb@metis.no>
Date: 10 Dec 2000 20:25:12 +0100
To: www-lib@w3.org
Message-ID: <whlmtoaxk7.fsf@viffer.computas.no>
>>>>> 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);
    HTRequest* request = HTRequest_new();
    HTAnchor* dest = HTAnchor_findAddress(url);
    int status = HTPutAnchor(src,dest,request);

Some references:
 [1] RFC2388, the definition of the multipart/form-data MIME type
 [2] RFC2046, section 5 describes multiparts, and the syntax of
     multipart boundaries
Received on Sunday, 10 December 2000 14:28:20 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:53 UTC