Php 后卷曲问题
这很有效,但只有一个问题, 我想要一种从变量中发布的数据中获取内容响应的方法,而不是像页面一样显示。请尝试以下操作:Php 后卷曲问题,php,curl,Php,Curl,这很有效,但只有一个问题, 我想要一种从变量中发布的数据中获取内容响应的方法,而不是像页面一样显示。请尝试以下操作: <?php $url = "http://website.com/folder/index.php"; $data = array('id' => 'R98s', 'name' => 'Bob', 'content' => 'Hello'); $handle = curl_init($url); curl_setopt($handle, CURLOPT_
<?php
$url = "http://website.com/folder/index.php";
$data = array('id' => 'R98s', 'name' => 'Bob', 'content' => 'Hello');
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_exec($handle);
?>
永远不要忘记
curl\u close($handle)代码>结尾。我一直认为你也需要这个
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE ); // return into a variable
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec( $ch ); // run!
curl_close($ch);
curl_close()可能在脚本终止时默认发生,不是吗?当变量超出范围时,可能会发生什么情况?你能更详细地解释一下吗?这与及时释放资源和整体良好的编程有关:当你不再需要文件/句柄/数据库连接时,将其释放。
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($handle)