Codeigniter return 500 for cURL

0

guys, I'm using cURL to send the data to a page and bring me the return, type an API

but returns error 500: The action you have requested is not allowed.

If I call the page directly through the browser it works, by cURL not

My function:

public function index () {

$api = curl_init();

$dados = array(
    'teste' => 1,
);

curl_setopt_array($api, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://example.com/api/info',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $dados,            
    //CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_SSL_VERIFYHOST => 2,
    //CURLOPT_REFERER => 'https://example.com'
));

$get = curl_exec($api);

$info = curl_getinfo($api);

if(!curl_exec($api)){
    die('Error: "' . curl_error($api) . '" - Code: ' . curl_errno($api));
}
echo "<pre>";
print_r($info);
echo "</pre>";

print_r($get);

curl_close($api);

} return this:

 Array
(
    [url] => https://example.com/api/info
    [content_type] => text/html; charset=ISO-8859-1
    [http_code] => 500
    [header_size] => 202
    [request_size] => 260
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [redirect_url] => 
    [primary_ip] => 127.0.0.1
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 127.0.0.1
    [local_port] => 37322
)

my example.com/api/info:

public function info(){
        phpinfo();
    }
    
asked by anonymous 26.06.2018 / 15:39

0 answers