phantomjs API 错误
phantomjs API error
我正在使用 https://phantomjscloud.com 生成网站的 pdf 快照。我正在使用一个非常基本的示例,如下所示:
$Foptions = new stdClass();
$Foptions->url = 'http://lr.boatsetter.com/boat/?id=1';
$Foptions->renderType = "pdf";
$optionsjson = json_encode($Foptions);
$url = 'http://PhantomJScloud.com/api/browser/v2/myapi/';
$payload = $optionsjson;
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $payload
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
file_put_contents('boat_1.pdf',$result);
这在 $Foptions->url 为 amazon.com 或 google.com 时完美运行。但不是我的例子。可能是什么错误?
我正在使用 http api 及其工作原理:
$headers = array( "Accept:" );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$wp_upload_dir = wp_upload_dir();
$upload_dir = $wp_upload_dir['basedir'] . '/pdf/';
$url = 'https://phantomjscloud.com/api/browser/v2/myapi/?request={url:%22'.get_home_url().'/boat/?id='.$boat_id.'%22,renderType:%22pdf%22}';
$path = $upload_dir."boat_".$boat_id.".pdf";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
$data = curl_exec($ch);
curl_close($ch);
$result = file_put_contents($path, $data);
if(!$result){
echo "error";
}else{
echo "success";
}
$file = $path;
$filename = 'Boat_'.$boat_id.'.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);
我正在使用 https://phantomjscloud.com 生成网站的 pdf 快照。我正在使用一个非常基本的示例,如下所示:
$Foptions = new stdClass();
$Foptions->url = 'http://lr.boatsetter.com/boat/?id=1';
$Foptions->renderType = "pdf";
$optionsjson = json_encode($Foptions);
$url = 'http://PhantomJScloud.com/api/browser/v2/myapi/';
$payload = $optionsjson;
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => $payload
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
file_put_contents('boat_1.pdf',$result);
这在 $Foptions->url 为 amazon.com 或 google.com 时完美运行。但不是我的例子。可能是什么错误?
我正在使用 http api 及其工作原理:
$headers = array( "Accept:" );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$wp_upload_dir = wp_upload_dir();
$upload_dir = $wp_upload_dir['basedir'] . '/pdf/';
$url = 'https://phantomjscloud.com/api/browser/v2/myapi/?request={url:%22'.get_home_url().'/boat/?id='.$boat_id.'%22,renderType:%22pdf%22}';
$path = $upload_dir."boat_".$boat_id.".pdf";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
$data = curl_exec($ch);
curl_close($ch);
$result = file_put_contents($path, $data);
if(!$result){
echo "error";
}else{
echo "success";
}
$file = $path;
$filename = 'Boat_'.$boat_id.'.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
@readfile($file);