cURL is not working with codeignier 3 |
In CodeIgniter 3.1.8. I used cURL.
Code: public function sample() I can not get any error or response from that. but the same code is working outside of Codeigniter. should I use an external library for that? or Should I make some changes to the code? I checked this one https://github.com/philsturgeon/codeigniter-curl but it is DEPRECATED.
Try error_reporting(E_ALL) - I suspect errors are disabled, pretty sure $args['file'] = ... should display a warning, as $args is not defined as array before setting a value to it.
What PHP version are you targeting? (07-25-2018, 12:59 AM)Pertti Wrote: Try error_reporting(E_ALL) - I suspect errors are disabled, pretty sure $args['file'] = ... should display a warning, as $args is not defined as array before setting a value to it. Thanks for you reply pertti, I am using PHP 7.1. and yes all errors are enabled on my portal I already checked error_reporting(E_ALL). but the same code is run outside of CodeIgniter.
The curl_init method returns a false if there is an error.
PHP Code: public function sample() Give that a try. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Use below code
public function sample() { $ch = curl_init(); $target_url = 'https://apiurl.com'; curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_ENCODING, ''); $args['file'] = new CurlFile($_SERVER['DOCUMENT_ROOT'].'/file/sample.docx'); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $response = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if($httpcode == 200 || $httpcode == '200') { print_r($response); } else { echo "httpcode : ".$httpcode; if ($response === false) { print_r('<br />cURL error: ' . curl_error($ch)); $error_message = curl_strerror($errno); echo "<br />cURL error ({$errno}):\n {$error_message}"; } } } If its return httpcode than after follow below link for verify exact error : 1) https://developer.mozilla.org/en-US/docs...TTP/Status 2) http://php.net/manual/en/function.http-r...e-code.php So you can move further easily.
In case someone needs it this is a CodeIgniter 3 CURL Library.
CodeIgniter : PHP Curl library with SSL Example What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Simple to pull in and use Guzzle HTTP Client for your needs. It's not just for CodeIgniter, so it works everywhere.
|
Welcome Guest, Not a member yet? Register Sign In |