php - 如何将 linux 命令 CURL 转换为 PHP

标签 php linux curl

我想将此 linux 命令控制台转换为 PHP 代码,以通过 curl 发送数据,

curl -X POST -d 'data[][street]=1' link.....

谢谢!!

最佳答案

$fields = 2;
$fields_as_string = "key=value&key2=value"    

//open the curl connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
// set the number of post fields
curl_setopt($ch,CURLOPT_POST, $fields);
// set the fields
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_as_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

不要忘记确保您已经启用了 curl php 扩展。

关于php - 如何将 linux 命令 CURL 转换为 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21602003/

相关文章:

php - 如何使用 php 框架 laravel 5.1 在 mysql 中正确插入时间值?

mysql忽略任何不同的值

curl - 为什么 Google Calendar API (oauth2) 响应为 'Insufficient Permission' ?

php - 如何获取 SSL 协议(protocol)版本 (php)

javascript - 尝试使用 js、jquery 和 PHP 上传图片时出错

linux - 循环停止

来自 thispersondoesnotexist.com 的 Curl 失败,结果为空

php - 从特定 id 名称开始的 DOM 中获取 div 数据

php - 如何使用 div id 作为 php var

java - 无法使用 Java 9 启动 solr