且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将linux命令CURL转换为PHP

更新时间:2023-02-16 20:04:23

$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.