简体   繁体   English

浏览器如何通过HTTP下载文件

[英]How's file downloaded by the browser over HTTP

我目前正在尝试准确地了解当浏览器将文件下载到桌面时会发生什么情况,特别是使用了多少个HTTP请求,该过程与仅获取图像或脚本之类的资源有何不同。等等。如果有人从这里开始设计一个进程,则A browser sends HTTP request

  1. A Browser sends an http request 浏览器发送http请求
  2. The server responds with the file to be downloaded, and adds some HTTP headers (which say that it's a file to be downloaded) usually along these lines: Content-Type: application/octet-stream Content-Disposition: attachment; filename="picture.png" 服务器以要下载的文件作为响应,并通常沿着以下几行添加一些HTTP标头(说这是要下载的文件): Content-Type: application/octet-stream Content-Disposition: attachment; filename="picture.png" Content-Type: application/octet-stream Content-Disposition: attachment; filename="picture.png"
  3. The Browser then handles the response according to user settings (usually asks for permission before saving) 然后,浏览器根据用户设置处理响应(通常在保存之前要求获得许可)

I know it's a bit of reading, but this is a good resource. 我知道这是一个有点阅读,但是是一个很好的资源。 Also, for a less intense introduction this helped me out quite a bit. 另外,对于不太激烈的介绍, 对我帮助很大。

As to the number of HTTP requests used the answer is one. 至于使用的HTTP请求数,答案是1。 There is a TCP handshake done then the request is transmitted, after that the response is sent back. 完成TCP握手,然后发送请求,然后将响应发送回去。 There is a little more involved if everything is over SSL/TLS, but that's all part of one HTTP request/response cycle. 如果一切都通过SSL / TLS进行,则需要更多的精力,但这只是一个HTTP请求/响应周期的一部分。

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

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