在不使用任何库的情况下在 HTTP 响应中发送位图文件
Send bitmap file in an HTTP response without using any libraries
我想在 HTTP 响应中发送一个位图文件,但我不知道该怎么做;我尝试了不同的方法,但都失败了。只能发送文本,我只想知道从哪里开始。这是相关代码
client_connection.sendall("HTTP/1.1 200 OK\n"
+"Content-Type: image/bmp\n"
+"Content-Lenth:%d"%size
+"\n"
+arr)
用什么代替 arr
?我正在将位图写入 test.bmp
文件。
您使用了错误的行尾标记,并且有很多拼写错误。 arr
是你的文件内容:
with open('test.bmp', 'rb') as bmp:
arr = bmp.read()
client_connection.sendall("HTTP/1.1 200 OK\r\n"
+ "Content-Type: image/bmp\r\n"
+ "Content-Length: %d\r\n" % len(arr)
+ "\r\n"
+ arr)
我想在 HTTP 响应中发送一个位图文件,但我不知道该怎么做;我尝试了不同的方法,但都失败了。只能发送文本,我只想知道从哪里开始。这是相关代码
client_connection.sendall("HTTP/1.1 200 OK\n"
+"Content-Type: image/bmp\n"
+"Content-Lenth:%d"%size
+"\n"
+arr)
用什么代替 arr
?我正在将位图写入 test.bmp
文件。
您使用了错误的行尾标记,并且有很多拼写错误。 arr
是你的文件内容:
with open('test.bmp', 'rb') as bmp:
arr = bmp.read()
client_connection.sendall("HTTP/1.1 200 OK\r\n"
+ "Content-Type: image/bmp\r\n"
+ "Content-Length: %d\r\n" % len(arr)
+ "\r\n"
+ arr)