python2 http服务端和客户端
server.py
import SimpleHTTPServer
import SocketServer
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write("hello")
PORT = 8000
handler = MyHandler
httpd = SocketServer.TCPServer(("", PORT), handler)
print "Serving at port", PORT
httpd.serve_forever()
client.py
import urllib2
url = 'http://10.1.1.100:8000'
response = urllib2.urlopen(url)
response_data = response.read()
print(response_data)