Welcome Guest, Not a member yet? Register   Sign In
cURL is not working with codeignier 3
#6

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.
Reply


Messages In This Thread
cURL is not working with codeignier 3 - by dhaval - 07-24-2018, 11:13 PM
RE: cURL is not working with codeignier 3 - by excellentwebworld - 08-11-2018, 12:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB