且构网

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

使用 PHP Curl 发布数据并检索响应?

更新时间:2023-02-24 14:13:16

您必须将 CURLOPT_RETURNTRANSFER 选项设置为 true.

You'll have to set the CURLOPT_RETURNTRANSFER option to true.

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

curl_close($ch);

对您的请求的响应将在 $result 变量中可用.

The response to your request will be available in the $result variable.