cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Data lost by multipart/form-data

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 14 Nov 2001 13:19:36 +0100 (MET)

On Wed, 14 Nov 2001, ZAN14211 wrote:

> I tried to post some data with multipart/form-data.
> Then '\n' code was contained, data was missing bordering on it.
>
> like this:
>
> $ch = curl_init( "http://myserver.co.jp/request_dump.cgi" );
>
> curl_setopt( $ch, CURLOPT_HEADER, 1 );
> curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
>
> $values = array( "field1"=>"value1-1\nvalue1-2",
> "field2"=>"value2" );
> curl_setopt( $ch, CURLOPT_POSTFIELDS, $values );

I took a tour into the inner workings of the php curl wrapper code and I've
now returned to tell about my findings! ;-)

When you pass an array to CURLOPT_POSTFIELDS, it is passed as a
multipart/form-data post exactly as you describe. The problem with this is
that it uses the libcurl function curl_formparse() to accomplish this, and
that is a lame function(*).

It does not support newlines in the contents like you tried here.

The wrapper should instead use the new (and much better) curl_formadd()
function for this purpose. It does not have this newline problem.

(*) = yet it was the only available one for a very long time.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-11-14