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)
标签:http,self,py,response,import,PORT,服务端,python2
From: https://www.cnblogs.com/xwjh/p/17728610.html