【发布时间】:2021-03-30 17:18:14
【问题描述】:
我在使用 laravel 控制器导出 kml 和 gpx 文件时遇到问题:对于 json 导出,我使用函数
public function mapExportJSON(Request $request) {
$client = new Client();
$http = $client->post(
'https://myurl' ,
[
'body' => json_encode(array('points' => $request->points)),
'headers' => [
'Cache-Control' => 'no-cache',
'Content-type' => 'application/json',
]
]
);
$result = $http->getBody()->getContents();
return response($result)
->header('Content-Disposition', 'attachment; filename=route.json');
}
我使用 xml 格式化程序,但它不起作用:(
public function mapExportKML(Request $request) {
$client = new Client();
$http = $client->post(
'https://myurl' ,
[
'body' => json_encode(array('points' => $request->points)),
'headers' => [
'Cache-Control' => 'no-cache',
'Content-type' => 'application/json',
]
]
);
$result = $http->getBody();
$formatter = Formatter::make($result, Formatter::JSON);
$xml = $formatter->toXml();
return response($xml)
->header('Content-Disposition', 'attachment; filename=route.kml')
->header('Content-Type', 'application/xml');
}
有人帮帮我吗?
【问题讨论】:
标签: xml laravel export kml formatter