PHP等效的CURL命令

时间:2013-02-17 15:07:25

标签: php http curl

以下CURL命令的PHP等价物是什么?

curl -X POST -d "html=<html><body><h1 style="color: red;">Hello World!</h1>" http://example.com/post"

1 个答案:

答案 0 :(得分:3)

尝试这样的事情:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/post');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$data = array('html' => '<html><body><h1 style="color: red;">Hello World!</h1>'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);

为了将来参考,在询问此类问题之前,阅读PHP's documentation并侦察other examples会很有用。