标签:
server.py
from wsgiref.simple_server import make_server from ex import application httpd=make_server(‘‘,8000,application) print ‘Serving Http on port 8000‘ httpd.serve_forever()
ex.py
def application(environ,start_response): start_response(‘200 OK‘,[(‘Content-Type‘,‘text/html‘)]) body=‘<ol>‘ for key,value in environ.iteritems(): body=‘‘.join([body,‘<li>%s:%s</li>‘ %(key,value)]) else: body=‘‘.join([body,‘</ol>‘]) return [body]
两文件方式在同一目录下,python server.py 启动
浏览器 访问 http://localhots:8000
或者使用
import urllib2 request=urllib2.urlopen(‘http://localhost:8000‘)
response=request.read()
做get 请求
标签:
原文地址:http://www.cnblogs.com/Citizen/p/4801547.html