python http服务器-多数据包中的内容

python http服务器-多数据包中的内容,python,Python,在学习http协议的同时,我用python创建了一个http服务器。我遇到了一个问题。我想将内容以多个数据包的形式发送到浏览器。我试过这个: conn.send("HTTP/1.0 200 OK") conn.send("\r\n") conn.send("Content-Type: application/force-download") conn.send("\r\n") conn.send("Content-Disposition: attachment; filename=file.tx

在学习http协议的同时,我用python创建了一个http服务器。我遇到了一个问题。我想将内容以多个数据包的形式发送到浏览器。我试过这个:

conn.send("HTTP/1.0 200 OK")
conn.send("\r\n")
conn.send("Content-Type: application/force-download")
conn.send("\r\n")
conn.send("Content-Disposition: attachment; filename=file.txt")
conn.send("\r\n")
conn.send("Content-length: "+str(file_length))
conn.send("\r\n\r\n")

c = 0
while download_data[c]:
  conn.send(download_data[c])

但它不起作用。浏览器只接收第一个数据包。谢谢你的建议。

我看不到任何地方
c
会发生变化,因此
下载数据[c]
的值也不太可能发生变化。您是否需要:

c = 0
while c < len(download_data):
    conn.send(download_data[c])
    c += 1
c=0
当c
您的
conn
download\u data
变量的类型是什么?conn是套接字对象,download\u data包含部分内容。谢谢,我很快就写了这个部分代码。我需要编辑的标题,它已发送所有。