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