python SimpleHTTPServer添加POST方法
实现功能比较简单。先在终端下运行该脚本,然后在浏览器打开localhost:8000即可看到当前目录下的文件
也可以do_GET和do_POST方法中添加更多的功能语句实现更丰富的功能。
[python]
mport SimpleHTTPServer
import SocketServer
import cgi
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
form = cgi.FieldStorage()
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
import SimpleHTTPServer
import SocketServer
import cgi
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
form = cgi.FieldStorage()
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ,hgxjwbc.com,ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
在do_GET方法中使用
[python]
print "hi"
print "hi"
会在终端(即服务器端)输出hi
而若使用
[python]
self.wfile.write("hi")
self.wfile.write("hi")
即可在浏览器端输出hi
也可在self.wfile.write()中使用HTML语句,在浏览器中显示网页
ps:自学成果,还望大神多多指点
也可以do_GET和do_POST方法中添加更多的功能语句实现更丰富的功能。
[python]
mport SimpleHTTPServer
import SocketServer
import cgi
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
form = cgi.FieldStorage()
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
import SimpleHTTPServer
import SocketServer
import cgi
PORT = 8000
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
form = cgi.FieldStorage()
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
Handler = ,hgxjwbc.com,ServerHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
在do_GET方法中使用
[python]
print "hi"
print "hi"
会在终端(即服务器端)输出hi
而若使用
[python]
self.wfile.write("hi")
self.wfile.write("hi")
即可在浏览器端输出hi
也可在self.wfile.write()中使用HTML语句,在浏览器中显示网页
ps:自学成果,还望大神多多指点
...全文
相关推荐
使用Python快速搭建HTTP服务和文件共享服务的实例讲解
今天小编就为大家分享一篇使用Python快速搭建HTTP服务和文件共享服务的实例讲解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
python101-simpleHTTPServer:simpleHTTPServer 的简单使用——Python 内置的 web 服务器
python101-simpleHTTPServer simpleHTTPServer 的简单使用——Python 内置的 web 服务器
Python通过命令开启http.server服务器的方法
主要给大家介绍了关于Python通过命令开启http.server服务器的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们随着小编来一起学习学习吧。
轻量级HttpServer.zip
轻量级HttpServer.zip
使用python SimpleHTTPServer 快速搭建Web服务器
NULL 博文链接:https://heipark.iteye.com/blog/1539404


Web 开发
