curl-and-python

Re: Setting content type for HTTPPOST?

From: Michael Wood <esiotrot_at_gmail.com>
Date: Tue, 12 Oct 2010 12:01:46 +0200

On 11 October 2010 20:16, <johansen_at_opensolaris.org> wrote:
> On Mon, Oct 11, 2010 at 07:02:36PM +0200, Michael Wood wrote:
>> Hi
>>
>> I'm using PycURL to upload a file but I'm having trouble figuring out
>> how to specify the content type of the file.  It's currently coming
>> through as text/plain and the server seems to be converting the DOS
>> line end characters to UNIX line end characters.  When the file is
>> uploaded, the server calculates the checksum to send back to the
>> client so that the client knows that the file is not corrupted, so
>> this EOL conversion breaks the checksum.
>>
>> At the moment I'm doing this:
>>
>>         pf = [("report", (pycurl.FORM_FILE, filename)),
>>               ("checksum", self.checksum)]
>>         curl.setopt(pycurl.HTTPPOST, pf)
>>
>> I see there's a FORM_CONTENTTYPE option, but I haven't noticed
>> documentation on it or exactly how to use it.  Perhaps I've been
>> looking in the wrong place, in which case I'd appreciate a pointer to
>> the right place :)
>
> At this point, the documentation is the code itself.  When in doubt, I
> look there first.  The HTTPPOST code handles the arguments as FORMTYPE,
> argument pairs.  This looks a lot like the interface used here:
>
> http://curl.haxx.se/libcurl/c/curl_formadd.html
>
> I believe that the following should work for you:
>
>        pf = [(pycurl.FORM_FILE, filename, pycurl.FORM_CONTENTTYPE,
>        content_type)]
>        curl.setopt(pycurl.HTTPPOST, pf)

After looking at the PycURL code I couldn't see why it would not work,
so I tried modifying the libcurl postit2.c example to add the content
type. I saw the same behaviour, so I've posted to the libcurl list
about it.

-- 
Michael Wood <esiotrot_at_gmail.com>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2010-10-12