无法导出 gpx 和 kml 文件,laravel

问题描述

我在使用 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',]
        ]
    );

    $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');

}

有人帮我吗?

解决方法

看起来您使用了不正确的格式化程序,请尝试以下操作

  $formatter = Formatter::make($result,Formatter::XML);
  $xml  = $formatter->toXml();

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...