3

I'm trying to send a POST request with cURL, but unfortunately I'm only receiving an empty string.

cURL:

<?php
echo "ID: " . $_POST["id"]; // here ID is not empty

$fields = array(
    'id' => urlencode($_POST["id"]),
    'name' => urlencode($_POST["name"])
);

$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "http://www.example.de/remote.php");
curl_setopt ($connection, CURLOPT_POST, true);
curl_setopt($connection, CURLOPT_POSTFIELDS, count($fields));
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($connection, CURLOPT_HEADER, 0);
$response = curl_exec($connection);
?>

Remote-Server:

<?php
   var_dump($_POST); // shows an empty array
?>
1
  • 2
    You're sending the number of fields, count($fields) in to CURLOPT_POSTFIELDS instead of the actual fields, is that intentional? Commented Apr 22, 2012 at 1:06

1 Answer 1

4

You need to remove the count($fields) and instead just use $fields

curl_setopt($connection, CURLOPT_POSTFIELDS, $fields);

Nowhere do you actually set the cURL option to send the fields

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

Comments

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.