I use PHP5.3 with CodeIgniter framework, also using TOAST - CodeIgniter Unit Testing library.
I need to test my controllers, it requires POST for variable passing. I tried cUrl and stream_context_create, both failed. (curl is enabled) However I can do it succesfully using POSTMAN with same body data. So, receiver works well, i have problem on sender.
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);
Also, i tried:
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);
Without knowing the error you're getting it's a little hard to diagnose but it could well be that your request is getting redirected (302 or 301 status code). That would drop the post data.
My .htaccess redirects a request if it doesn't end in a slash, so maybe try adding a slash at the end of the URL?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.