以下CURL命令的PHP等价物是什么?
curl -X POST -d "html=<html><body><h1 style="color: red;">Hello World!</h1>" http://example.com/post"
答案 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会很有用。