Andurit
Andurit

Reputation: 5762

ERROR 404 - The requested resource is not available.[PHP]

I make some CURL request on REST API, which looks like this:

$data = array (
    "caseNumber" => "123456789" 
    );

// json encode data

$data_string = json_encode($data); 

// the token

$token = 'eyJhbGciOiJIUzI1NiJ9';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host.$path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/x-www-form-urlencoded',                                                                                
    'Authorization: Bearer '.$token
));       

// execute the request
$output = curl_exec($ch);   
echo $output;

In general it looks really OKEY from my point of view, how ever I try this ECHO just kick apache ass.

I already try to var_dump() and print() it as well, but still same result and without any better description I don't know how to debug this. Can somebody give an advise or is here anyone who see a bug in my code? Thanks

Upvotes: 0

Views: 1213

Answers (1)

borfast
borfast

Reputation: 2274

$output should be a boolean value indicating the success or failure of the request. It will not contain anything else. In order to get the result of the operation, try something like this:

$output = curl_exec($ch);

if ($output === false) {
    print 'Error: ' . curl_error($ch);
} else {
    print 'Request completed. Output: ' . $output;
}

// Close handle
curl_close($ch);

Upvotes: 1

Related Questions