2
我使用PHP5.3與CodeIgniter框架,也使用TOAST-CodeIgniter單元測試庫。PHP Post請求發送
我需要測試我的控制器,它需要POST變量傳遞。我試過cUrl和stream_context_create,都失敗了。 (curl已啓用)但是,我可以使用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);
也看到了這一點。 – catbadger