我想使用Command从终端执行DomPDF下载。 CLI命令使用Guzzle执行API调用。我做了一个非常简单的设置。
问题
500服务器错误
[GuzzleHttp\Exception\ServerException]
Server error: `GET http://localhost:8888/pdf` resulted in a `500 Internal S
erver Error` response:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow (truncated...)
API调用
命令
php artisan pdf
项目结构
SourceCode
路线
Route::get('pdf', 'PDFController@downloadPDF');
PDFCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use GuzzleHttp\Client as GuzzleClient;
class PDFCommand extends Command
{
protected $signature = 'pdf';
protected $description = 'download pdf';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$client = new GuzzleClient;
$client->request('GET', 'http://localhost:8888/pdf');
}
}
PDFController.php
<?php
namespace App\Core;
use App\Http\Controllers\Controller;
use Barryvdh\DomPDF\Facade as PDF;
class PDFController extends Controller
{
private $pdf;
private $client;
public function downloadPDF()
{
$this->pdf = PDF::loadView('report');
return $this->pdf->download('report.pdf');
}
}
rapport.blade.php
<!doctype html>
<html>
<head>
<title>Rapport</title>
</head>
<body>
<h1>TEST</h1>
<p>Dit is een test</p>
</body>
</html>
答案 0 :(得分:0)
你能读一下这个错误吗?当您收到500 Server Error
时,响应中还包含带有错误说明的HTML。它应该包含一个错误的解释。只需将其保存到文件(file_put_contents('...', $response->getBody()->getContents())
)或以其他方式阅读。