python - 如何在 Twisted HTTP 服务器上强制下载文件?

标签 python http url twisted

非常简单的问题,我目前希望用户下载(而不是打开)存储在 python Twisted Web 服务器上的 csv 文件。访问其 URL 时,该文件当前会在浏览器中打开。

最佳答案

你可以像这样设置响应头:

request.responseHeaders.setRawHeaders(
    'Content-Disposition', ['attachment; filename="foo"'])

关于python - 如何在 Twisted HTTP 服务器上强制下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11944011/

相关文章:

javascript - 自定义 HTTP header 或 cookie?自定义身份验证/授权如何帮助 CSRF?

url - Drupal 7 : URL alias is getting ignored on pages when "provide a menu link" is unchecked on multilingual site

url - Magento 多语言 - 语言的双重变化导致 404(或如何在商店而不是 View 中更改语言)

python - eBay API 在沙盒中返回 'Application ID invalid',但在生产中有效

python - 替代已弃用的 sqlite pragma "default_cache_size"

python - 通过 macports 安装 Py.test 时出错

python - 扭曲的 adbapi cp_reconnect 不工作

ruby - HTTP协议(protocol): How does one figure out where a site's homepage is located

python - type 是 Python 中所有类的父类(super class)吗?

html - 为什么我们使用相对方案//而不是 http ://or https://?