Answer the question
In order to leave comments, you need to log in
How to display received PDF stream by curl?
Tell me this question, I work with the API of one delivery company. The API structure is implemented according to the REST architecture. Communication is done through JSON messages.
In some requests, I receive response data in the form of an array, there are no problems with this. And some "contain a stream with a pdf file as an array of bytes (begins with "%PDF")".
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_URL, "http://sierra.pickpoint.ru/api/".$type);
curl_setopt($curl, CURLOPT_POST, $postType);
if($postType) curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($request));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
if($data === false) return false;
return $data;
Answer the question
In order to leave comments, you need to log in
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
echo $data;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question