开发者

POST something to URL without a form?

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 POSTing my code was:

$html_body = str_replace("\n", "", $html_body);
$html_body = str_replace("\t", "", $html_b开发者_StackOverflowody);
$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


this is everything what should know about curl

http://us2.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;


This article lays out how to do a POST in PHP programmatically without a form. http://davidwalsh.name/execute-http-post-php-curl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜