Restler,没有强制下载设置为true的数据?

时间:2013-12-27 13:46:15

标签: php json restler

我这里有一个奇怪的问题, 使用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就是一个例子,还有更多可能的类型)

1 个答案:

答案 0 :(得分:1)

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

如果我们要覆盖此默认行为,我们需要停止执行,只需在api方法中添加die / exit,如下所示

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

HTH

相关问题