简体   繁体   English

在node.js上使用http.get下载zip文件

[英]Downloading zip files with http.get on node.js

I'm having problem downloading a file from URL using http.get. 我在使用http.get从URL下载文件时遇到问题。 Response statusCode returns as 302, but when I try the same url with Firefox using HttpFox extension I can see a status code 200 and an additional header, "content-disposition: inline; filename=test.zip". 响应statusCode返回为302,但是当我使用Firefox使用HttpFox扩展名尝试相同的URL时,我可以看到状态码200和一个附加标头“ content-disposition:inline; filename = test.zip”。 Browsers handle these URL's correctly, and open a save as dialog. 浏览器可以正确处理这些URL,然后打开“另存为”对话框。 How should I handle this URL in Node.js? 我应该如何在Node.js中处理此URL?

"Response statusCode returns as 302" means redirect to another URL. “响应statusCode返回为302”表示重定向到另一个URL。

Browsers handles such response automatically. 浏览器会自动处理此类响应。 You have to do that by hands. 您必须手动完成。 The new URL is provided in the Location header. 新的URL在Location标头中提供。 Just do another http.get from this URL. 只需从此URL执行另一个http.get。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM