4

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.

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I've been looking for that 4 hrs. Haha! Thanks so much man =)
1

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...?

4 Comments

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
yeah, doh! I just read the manual, and my answer was rubbish! sorry, I can't help
what about curl_setopt ($curlSession, CURLOPT_POST, 1); instead of 'true'. Again another guess from my own cut-and-paste code
Nope ;) that shouldn't matter
0

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

2 Comments

then I'm stuck too, sorry again
No probs man, I've been looking for an answer for about 4 hrs now ;) Thanks for your efforts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.