[英]Python Web Server and File Download
I've made this simple HTTP server in Python : 我已经在Python中制作了这个简单的HTTP服务器 :
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
What I want to do now, but I don't know how, is the following: 我现在想做的,但我不知道怎么做的是:
When I visit http://localhost:8000/my/path/download?documentID=100
, a document (particularly a PDF file) will start being downloaded automatically. 当我访问http://localhost:8000/my/path/download?documentID=100
,文档(尤其是PDF文件)将开始自动下载。 Of course, I have more documents but I want them to be identified by the get paramater documentID
当然,我有更多文档,但我希望通过get参数documentID
进行标识
What is the easiest way to achieve this? 最简单的方法是什么? thanks 谢谢
You have to write a new handle. 您必须编写一个新的句柄。 http://fragments.turtlemeat.com/pythonwebserver.php shows a simple example. http://fragments.turtlemeat.com/pythonwebserver.php显示了一个简单的示例。
You have to: 你必须:
alternative: 替代方案:
http://localhost:8000/my/path/1.pdf
和简单易用的链接,例如http://localhost:8000/my/path/1.pdf
Greets Kuishi 向奎石致意
PS: English isn't my native language, sorry PS:英语不是我的母语,对不起
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.