0
我总结了以下脚本,我想返回的“Hello World!(‘192.168.0.162’,48344)鲍勃”当我的浏览器我有CGI FieldStorage只会返回None?
server:8081/?first_name=bob
然而,当我运行下面的程序它返回的Hello World!( '192.168.0.162',48344)无
#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import cgi, cgitb
x = "1"
PORT_NUMBER = 8081
cgitb.enable()
#This class will handles any incoming request from
#the browser
class myHandler(BaseHTTPRequestHandler):
#Handler for the GET requests
def do_GET(self):
form = cgi.FieldStorage()
first_name = form.getvalue('first_name')
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Send the html message
self.wfile.write("Hello World !")
self.wfile.write(self.client_address)
self.wfile.write(first_name)
return
try:
#Create a web server and define the handler to manage the
#incoming request
server = HTTPServer(('', PORT_NUMBER), myHandler)
print 'Started httpserver on port ' , PORT_NUMBER
#Wait forever for incoming htto requests
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down the web server'
server.socket.close()
有什么不对?
它的工作原理,但如果有人正在努力解决如何做到这一点,它会形成一个字典,其中所有的查询可以查询与查询名称作为关键,例如form ['first_name']将返回[ 'bob'] – user2420338
是的,文档的细节点,但也许我应该在我的例子中包括它。最好。 – codnodder