PHP等价于CURL命令 [英] PHP Equivalent of CURL command
本文介绍了PHP等价于CURL命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下CURL命令的PHP等效项是什么?
What's the PHP equivalent of the following CURL command?
curl -X POST -dhtml =< html>< body> ;< h1 style =color:red;> Hello World!< / h1> http://example.com/post
推荐答案
尝试这样:
$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等价于CURL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文