【发布时间】:2017-07-13 21:44:35
【问题描述】:
我使用 PHP5.3 和 CodeIgniter 框架,也使用 TOAST - CodeIgniter 单元测试库。
我需要测试我的控制器,它需要 POST 来传递变量。我尝试了 cUrl 和 stream_context_create,都失败了。 (卷曲已启用)但是我可以使用具有相同正文数据的 POSTMAN 成功地做到这一点。所以,接收者工作正常,我的发送者有问题。
curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://localhost:8080/myApp/index.php?/systemAdministration/runScheduledETL');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array('id' => $id));
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
另外,我试过了:
url = 'http://localhost:8080/myApp/index.php?/systemAdministration/runScheduledETL';
$data = array('id' => $id);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
【问题讨论】:
-
也看到了这个。
标签: php codeigniter curl post