擅长:python、mysql、java
<p>可以使用http.serverpython3中的模块。我在下面贴了一个例子。适应你的需要。你知道吗</p>
<pre><code>import http.server
import socketserver
PORT = 8000
class ScriptHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
""" Handle POSTed script """
try:
result = eval(self.rfile.read())
self.send_response(200,'Ok')
self.wfile.write(result)
except:
#handle errors
httpd = socketserver.TCPServer(("", PORT), ScriptHTTPRequestHandler)
print("serving at port", PORT)
httpd.serve_forever()
</code></pre>
<p>服务器运行后,创建一个HTML表单,操作为“http://localhost:8000/“,应该执行上面的do\u POST方法。将HTML文件放在服务器脚本的同一文件夹或子目录中。有关详细信息,请参见<a href="http://docs.python.org/py3k/library/http.server.html" rel="nofollow">http.server python docs</a>。你知道吗</p>