Loading

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)
posted @ 2023-09-25 18:39  小维江湖  阅读(146)  评论(0编辑  收藏  举报