Skip to main content
 首页 » 编程设计

python之使用 python 的 http 服务器时如何设置内容类型

2025年05月04日7fff_TT

我尝试使用 send_header('Content-Type', 'text/html')。但是,这不起作用。

请您参考如下方法:

以下在派生自 http.server.BaseHTTPRequestHandler 的类中对我有用:

self.send_response(200) 
self.send_header("Content-type", "text/plain") 
self.end_headers() 
# Your response body follows with self.wfile.write() 

查看更多here和 here .