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

curl-and-php

RE: Posting multiple values for a single key

From: YupLounge website analyse en optimalisatie <info_at_yuplounge.com>
Date: Fri, 4 Jul 2008 10:14:35 +0200

Hi Daniel,
I believe multipart is possible:

$postfields['salaries'] = urlencode(serialize($salaries));
$postfields['morepost'] = 'wwwwww';
$postfields['muchmorepost'] = 'zzzzwwwwww';

curl_setopt ($conn, CURLOPT_POSTFIELDS , $postfields );

makes it a multi part post. But your right, you have to build your
postfields before posting.

Example scripts:
PHPdocument1.php:
<?php
$salaries["Bob"] = 2000;
$salaries["Sally"] = 4000;
$salaries["Charlie"] = 600;
$salaries["Clare"] = 0;

$postfields['salaries'] = urlencode(serialize($salaries));
$postfields['morepost'] = 'wwwwww';
$postfields['muchmorepost'] = 'zzzzwwwwww';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://yourdomain/PHPDocument2.php' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields );
$response = curl_exec( $ch );
curl_close($ch);
echo $response;
?>

PHPdocument2.php
<?php
print_r($_POST);
print_r(unserialize(urldecode($_POST['salaries'])));
?>

Keep up the good work Daniel (and hopefully they once listen to you at
Zend/PHP)

Willem.

-----Oorspronkelijk bericht-----
Van: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] Namens Daniel Stenberg
Verzonden: vrijdag 4 juli 2008 9:26
Aan: curl with PHP
Onderwerp: RE: Posting multiple values for a single key

On Fri, 4 Jul 2008, YupLounge website analyse en optimalisatie wrote:

> Posting an associative array with php-curl is possible After hours of work
I
> once came up with the following solution:

[...]

> The only way you can send this is by serialize and urlencode. You must
> urlencode it because otherwise [] are seen as new POST-fields:

Right, but by doing the serializing stuff you also no longer make it a
multipart formpost...

-- 
  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-07-04