【问题标题】:Restler, not serving data with force download set to true?Restler,没有在强制下载设置为 true 的情况下提供数据?
【发布时间】:2013-12-27 13:46:14
【问题描述】:

我有一个奇怪的问题, 使用restler api时,即使我强行将其设置为不同的内容,标题内容类型似乎也会重置...... 好像 $r = new Restler(); $r->setSupportedFormats('JsonFormat'); 始终将其重置为“Content-Type: application/json; charset=utf-8”

那么,我可以通过什么方式手动将默认的 mime 类型覆盖为我想要的类型? 除此之外,似乎没有任何问题,这是您请求文件下载时的外观:Cache-Control: no-cache, must-revalidate Connection: Keep-Alive Content-Disposition: attachment; filename="test.pdf" Content-Encoding: gzip Content-Language: en Content-Length: 25 Content-Type: application/json; charset=utf-8

这是我在 phpcode 中设置的:

header("Content-type: application/pdf"); header("Content-Length: ". $data["Size"]); header('Content-Disposition: attachment; filename="'. $data["Name"].'"');

任何帮助强制它作为我喜欢的内容类型? (jftr、pdf就是一个例子,还有很多可能的类型)

【问题讨论】:

    标签: php json restler


    【解决方案1】:

    在我们从 api 方法返回结果后,Restler 设置标头

    如果我们想覆盖这个默认行为,我们需要停止进一步执行,只需在你的 api 方法上添加 die/exit 如下所示

    header("Content-type: application/pdf"); 
    header("Content-Length: ". $data["Size"]); 
    header('Content-Disposition: attachment; filename="'. $data["Name"].'"');
    die();
    

    HTH

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多