我是Tornado框架的新手。当我设置头文件类型为application/pdf
时,它只采用默认的MIME类型,即plian/text
。这是我的代码:
class MainHandler(tornado.web.RequestHandler):
def get(self):
ifile = open("requirements.txt", "r")
self.set_header('Content-Type', 'application/pdf; charset="utf-8"')
self.set_header('Content-Disposition', 'attachment; filename="test.pdf"')
#print(self.list_headers())
self.write(ifile.read())
在网页浏览器中成功下载。链接为http:/203.193.173.102:8888/。 但是当我打开PDF文件时,它无法打开。有人能帮忙吗?谢谢。
requirement.txt
而不是test.pdf
? - falsetru