negative negative -4 years ago 87
PHP Question

Can't Understand What Is the issue?

I am just trying to get some data from my created api. whenever i am trying to get data from it. it shows me error message of my api. here is the code, please help me.

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "My/Url/Call",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array(
"Authorization: Basic YXNoaXNoQGNyZW9sZXN0dWRpb3MuY29tOkNyZW9sZUAxMjM="
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

?>


Is is because i am using basic authentication?

Answer Source

seems like you have done authentication using some method, either get or post.

CURLOPT_CUSTOMREQUEST => "GET"

try to add this line if you are doing this call using get method. else use it as POST.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download