我计划按以下方式对服务器上的php文件进行查询:
example.com/download.php?value=7
如果此值满足某一条件,则服务器应响应实际内容。如果值不能满足此条件,我希望服务器使用某种类型的'null‘值进行响应。最好的做法是创建一个空的临时文件并返回这个文件,还是有一种更“标准”的响应方式--没有什么可下载的?
发布于 2015-07-07 15:55:40
在这种情况下,最好的响应是让服务器返回404错误。从规范中:
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable.
最好的方法可以在如何在PHP中创建错误404?找到
发布于 2015-07-07 16:01:32
本例中的最佳实践是返回一个有意义的HTTP响应代码。如果请求是针对丢失的文件或资源的,或者是400次错误的请求,则如果请求格式不正确,则可以选择404 NOT。查看本教程以获得更多RESTful最佳实践。
https://stackoverflow.com/questions/31281294
复制