Reputation: 151
I need a php page, when loaded, to send a POST request automatically without using a submit button or any user input. I don't need to do anything with the response.
I simply need to POST "8" to www.mydomain.com
$url = 'http://www.mydomain.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 8);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
What am I doing wrong?
Upvotes: 1
Views: 120
Reputation: 191749
Kind of a strange request .. you should consider using a key for the value of 8.
You can, however, get the POST body on http://www.mydomain.com/
by reading 'php://input'
.
//on www.mydomain.com/index.php
echo file_get_contents('php://input'); //8
By the way you also have $curl
instead of $ch
on the third setopt.
Upvotes: 0
Reputation: 1049
Try this:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('data' => 8));
On your domain edit script to:
echo $_POST['data'];
Upvotes: 2