![]() |
cURL is not working with codeignier 3 - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: cURL is not working with codeignier 3 (/showthread.php?tid=71270) |
cURL is not working with codeignier 3 - dhaval - 07-24-2018 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. RE: cURL is not working with codeignier 3 - Pertti - 07-25-2018 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? RE: cURL is not working with codeignier 3 - dhaval - 07-25-2018 (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. ![]() RE: cURL is not working with codeignier 3 - Pertti - 07-25-2018 Did I understood it right, it never gets to the die('--------------here-----------------'); ? If not, add echo '1'; ... echo '2'; every few lines of code, and you should see at what point does it break. RE: cURL is not working with codeignier 3 - InsiteFX - 07-25-2018 The curl_init method returns a false if there is an error. PHP Code: public function sample() Give that a try. RE: cURL is not working with codeignier 3 - excellentwebworld - 08-11-2018 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/Web/HTTP/Status 2) http://php.net/manual/en/function.http-response-code.php So you can move further easily. RE: cURL is not working with codeignier 3 - InsiteFX - 08-11-2018 In case someone needs it this is a CodeIgniter 3 CURL Library. CodeIgniter : PHP Curl library with SSL Example RE: cURL is not working with codeignier 3 - skunkbad - 08-11-2018 Simple to pull in and use Guzzle HTTP Client for your needs. It's not just for CodeIgniter, so it works everywhere. |