-1
我在學習http協議的同時在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.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])
但它不起作用。瀏覽器只接收第一個數據包。感謝您的建議。
你的''conn''和''download_data''變量的類型是什麼? – 2013-05-10 13:06:15
conn是套接字對象,download_data包含部分內容。 – 2013-05-10 13:16:50