Reputation: 3691
Can I POST
something to a URL and grab the result without a form and a submit button in PHP? If so, how does that work?
Thanks, Ryan
UPDATE
After a lot of trial and error, I got it to working.
I used the method described in the accepted answer, but what I had to do additionally before POST
ing my code was:
$html_body = str_replace("\n", "", $html_body);
$html_body = str_replace("\t", "", $html_body);
$html_body = urlencode($html_body);
I had to add those for my purpose and you may not need them, but just keep it in mind.
-Ryan
Upvotes: 2
Views: 4646
Reputation: 25564
this is everything what should know about curl
https://www.php.net/manual/en/book.curl.php
and this will POST without form as easy as:
$ch = curl_init("www.example.com/curl.php?option=test");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
Upvotes: 2