cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLOPT_WRITEDATA required in HTTP post?

From: John Wood <jdmwood_at_gmail.com>
Date: Fri, 28 Nov 2008 16:08:18 +0000

Not sure if this is a bug or just me making a mistake.

I was using libcurl to do a multi part form upload using HTTP post.

It worked 95% of the time.

Then occassionally it would fail with the error "Failed writing body".

It was occurring when libcurl was parsing the last received HTTP response
(the "HTTP OIK" response).

I tracked it down to sendf.c. When it was pushing the data out, whatever it
was writing to, didn't accept all the bytes.

Then, I realised that I hadn't actually set CURLOPT_WRITEFUNCTION, so it was
set to the default (which I think writes to a file). However, I also hadn't
set CURLOPT_WRITEDATA.

So, anyway, I explicitely set CURLOPT_WRITEFUNCTION to point to a dummy
function which just discarded the data, and my problem went away.

So my questions/comments are:

1. Do you explicitely need to set either/both CURLOPT_WRITEFUNCTION and
CURLOPT_WRITEDATA when using HTTP POST? I hadn't set them because I wasn't
interested in the response from the server (beyond whether it returned HTTP
200)

2. If you do need to set them, why does it work most of the time? In my
example, were the responses getting dumped to an internal file/buffer which
was getting full or something?

If you do need to explicitely set them, then shouldn't libcurl return error
and complain that you haven't set it up properly?

Regards,

John
Received on 2008-11-28