简体   繁体   English

CURL 命令的 PHP 等效项

[英]PHP Equivalent of CURL command

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

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

Try something like this:尝试这样的事情:

$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);

For future reference, it'd be useful to read PHP's documentation and scout out other examples before asking this type of question.为了将来参考,在提出此类问题之前阅读PHP 的文档并寻找其他示例会很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM