我正在尝试创建类似代理(在 PYTHON 中)以供下载,但出现错误。我想强制用户下载文件,而是在屏幕上打印(二进制代码)。这是我的代码:我正在做的是...从另一台服务器下载文件,同时尝试将此文件发送到客户端。所以是这样的:REMOTE_SERVER -> MY_SERVER -> CLIENT,而不必将文件保存在我的服务器中。有谁可以帮助我做错了什么?
myfile = session.get(r.headers['location'], stream = True)
print "Content-Type: application/zip\r\n"
print "Prama: no-cache\r\n"
print "Expires: 0\r\n"
print "Cache-Control: must-revalidate, post-check=0, pre-check=0\r\n"
print "Content-Type: application/octet-stream\r\n"
print "Content-Type: application/download\r\n"
print "Content-Disposition: attachment; filename=ternos.205.zip\r\n"
print "Content-Transfer-Encoding: binary\r\n"
print "Content-Length: 144303765\r\n"
#print "Accept-Ranges: bytes\r\n"
print ("\r\n\r\n")
#with open('suits.zip', 'wb') as f:
for chunk in myfile.iter_content(chunk_size=1024):
if chunk:
sys.stdout.write(chunk)
sys.stdout.flush()
似乎标题无关紧要,因为我已经尝试了数百万个不同的标题..强制下载等...但没有任何反应..