如何将linux命令CURL转换为PHP [英] How convert linux command CURL to PHP
本文介绍了如何将linux命令CURL转换为PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将此linux命令控制台转换为PHP代码,通过curl发送数据
I want to convert this linux command console to PHP code, to send data via curl,
curl -X POST -d 'data[][street]=1' link.....
/ p>
Thanks!!
推荐答案
$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扩展。
Don't forget to make sure you've enabled the curl php extension.
这篇关于如何将linux命令CURL转换为PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文