views:

1573

answers:

3

Greets.

So, I'm running Fedora Core 8 on an Amazon EC2. I installed httpd, php5 and libcurl, and a bunch of other stuff. Seemed to be working great, but then I realized that POST data isn't being sent by curl in my php scripts. Same request in the command line works tho. I also ran the same php scripts on my local machine (Win XP) and another remote machine (Ubuntu), and they run fine, the POST data is being sent, but not on the FC8. Does it require any special configuration? Any firewall issues?

Here's the PHP code:

error_reporting(E_ALL);
$ch = curl_init("http://foller.me/tmp/postdump.php");
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "something=somewhere");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 0);

$response = curl_exec($ch);

echo $response;
curl_close($ch);

Here's the corresponding curl command:

curl -d "something=somethingelse" http://foller.me/tmp/postdump.php

I also found the corresponding entry in the apache error_log, and here's what I came up with:

* About to connect() to foller.me port 80 (#0)
*   Trying 75.101.138.148... * connected
* Connected to foller.me (75.101.138.148) port 80 (#0)
> GET /tmp/postdump.php HTTP/1.1
Host: foller.me
Accept: */*

< HTTP/1.1 200 OK
< Date: Tue, 07 Jul 2009 10:32:18 GMT
< Server: Apache/2.2.9 (Fedora)
< X-Powered-By: PHP/5.2.6
< Content-Length: 31
< Connection: close
< Content-Type: text/html; charset=UTF-8
< 
* Closing connection #0

The POST data isn't being sent, see? Any ideas?

Thanks in advance everyone. ~ K.

A: 

Not an expert in this field but I've got my own working code which works slightly differently. Maybe this will help

// Open the cURL session
 $curlSession = curl_init();

 // Set the URL
 curl_setopt ($curlSession, CURLOPT_URL, $url);

It does the curl_init() first then sets the url, then later...

$rawresponse = curl_exec($curlSession);

i.e I have no idea but perhaps setting the url after makes a difference somehow...?

David Archer
Thanks for the attemp David, but unfortunatelly it didn't change anything. It does work on my two other machines though ;) but not where I want it to, hehe
kovshenin
yeah, doh! I just read the manual, and my answer was rubbish! sorry, I can't help
David Archer
what about curl_setopt ($curlSession, CURLOPT_POST, 1); instead of 'true'. Again another guess from my own cut-and-paste code
David Archer
Nope ;) that shouldn't matter
kovshenin
A: 

Also saw this post where it suggests sending the post fields as an array instead of string

David Archer
Tried it.. Nope :(
kovshenin
then I'm stuck too, sorry again
David Archer
No probs man, I've been looking for an answer for about 4 hrs now ;) Thanks for your efforts
kovshenin
+3  A: 

Looks as if this turns the request from POST to GET:

curl_setopt($ch, CURLOPT_NOBODY, 0);

Remove that line and it works.

CURLOPT_NOBODY

A non-zero parameter tells the library to not include the body-part in the output. This is only relevant for protocols that have separate header and body parts.

BlaM
I've been looking for that 4 hrs. Haha! Thanks so much man =)
kovshenin
and we all learn something new :-)
David Archer