posting with cURL - postfields array won't work
- From: "zorro" <myahact@xxxxxxxx>
- Date: 27 Dec 2006 16:00:25 -0800
Hello,
I'm really stumped about this one. The problem below happens when i'm
posting to a particular web site but there's no problem when I post to
my online testing server.
this works for both the web site and my testing server:
curl_setopt($curl, CURLOPT_POSTFIELDS, "clown=bozo" );
this works only for my testing server:
curl_setopt($curl, CURLOPT_POSTFIELDS, array('clown'=>'bozo') );
In this case the response from the web site is empty, no headers,
nothing, and there is no cURL error.
I need to use an array for the postfields because I will eventually be
uploading a file thusly:
array('myfile'=>''@c:/images/clowns/bozo.gif").
I searched the web and all I could find was some people append "\n" to
the posted values, so i tried that but to no avail:
array('clown'=>"bozo\n")
the full code:
$curl = curl_init();
$cookiejar =
$_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF']).'/cookiejar.txt';
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiejar );
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiejar );
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_MAXREDIRS, 2);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, array('clown'=>'bozo') );
curl_setopt($curl, CURLOPT_URL, 'http://www.somesite.com/form.htm');
$response = curl_exec($curl);
echo $response;
.
- Follow-Ups:
- Prev by Date: Re: [PHP] PHP & podcasts
- Next by Date: Re: PHP MAIL + HOTMAIL
- Previous by thread: PHP & podcasts
- Next by thread: Re: posting with cURL - postfields array won't work - SOLUTION
- Index(es):
Relevant Pages
|