我需要关于下面 handler 的帮助:
class MyHandler(http.server.BaseHTTPRequestHandler):
def do_HEAD(client):
client.send_response(200)
client.send_header("Content-type", "text/html")
client.end_headers()
def do_GET(client):
if client.path == "/":
client.send_response(200)
client.send_header("Content-type", "text/html")
client.end_headers()
client.wfile.write(load('index.html'))
def load(file):
with open(file, 'r') as file:
return encode(str(file.read()))
def encode(file):
return bytes(file, 'UTF-8')
我知道了,函数load()
是文件中的某个其他人。通过我的HTTP处理程序发送HTML页面似乎可以工作,但如何发送图像?我需要如何编码它,以及应该使用什么Content-type
?非常感谢您的帮助!
(附注:如果连接到我的http服务器,则希望在浏览器中看到发送的图像。)