V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Dive into HTML5
http://diveintohtml5.org/
duanzs
V2EX  ›  HTML

index.html 放在服务器上,浏览器输入地址链接是下载而不是打开

  •  
  •   duanzs · 2020-09-23 15:05:01 +08:00 · 3457 次点击
    这是一个创建于 1282 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我把一个 html 文件放在公司的云存储上,然后在浏览器输入地址链接,我想要的是打开这个 html,但是谷歌浏览器直接把这个 html 文件下载了,并不是解析 html

    为什么是下载不是打开?为什么将 html 放在服务器上就可以?有什么区别?

    18 条回复    2020-09-23 15:41:26 +08:00
    liyang5945
        2
    liyang5945  
       2020-09-23 15:07:33 +08:00
    HTTP content-type
    duanzs
        3
    duanzs  
    OP
       2020-09-23 15:07:57 +08:00
    自问自答一下:有可能是协议不同,放在服务器上走的是 http,放在存储上走的是 file 协议,具体我就不懂了,欢迎大佬补充?
    duanzs
        4
    duanzs  
    OP
       2020-09-23 15:14:36 +08:00
    @liyang5945
    @songjiaxin2008
    两位大佬,content-type 这个东西不是请求相关的吗,跟本身文件有关系?
    Tink
        5
    Tink  
       2020-09-23 15:17:11 +08:00
    跟协议没啥关系,都是 http,楼上两位已经说清楚了
    Content-Type:text/html ;
    lxk11153
        6
    lxk11153  
       2020-09-23 15:20:31 +08:00
    你看看区别在哪: curl -I 'https://xhgxa.ml/index.html'
    duanzs
        7
    duanzs  
    OP
       2020-09-23 15:20:49 +08:00
    @Tink 这是响应结果,指定 Content-Type: text/html 了,还是下载


    Access-Control-Allow-Headers: DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization
    Access-Control-Allow-Methods: GET, POST, OPTIONS
    Access-Control-Allow-Origin: *
    Cache-Control: max-age=0
    Content-Disposition: attachment; filename="test.html"
    Content-Encoding: gzip
    Content-Type: text/html
    Date: Wed, 23 Sep 2020 07:18:39 GMT
    ETag: W/"fef40692c82492577988854f508d411d"
    Expires: Wed, 23 Sep 2020 07:18:39 GMT
    Last-Modified: Wed, 23 Sep 2020 07:15:26 GMT
    Server: openresty
    Transfer-Encoding: chunked
    Vary: Accept-Encoding
    x-jss-request-id: 9338D2040B2AB5C3
    duanzs
        8
    duanzs  
    OP
       2020-09-23 15:21:31 +08:00
    @lxk11153 404
    File not found

    The site configured at this address does not contain the requested file.

    If this is your site, make sure that the filename case matches the URL.
    For root URLs (like http://example.com/) you must provide an index.html file.

    Read the full documentation for more information about using GitHub Pages.

    GitHub Status — @githubstatus
    YuxiangLuo
        9
    YuxiangLuo  
       2020-09-23 15:22:39 +08:00
    duanzs
        10
    duanzs  
    OP
       2020-09-23 15:24:59 +08:00
    @YuxiangLuo 我不是要下载这个文件,我想打开这个文件
    duanzs
        11
    duanzs  
    OP
       2020-09-23 15:25:55 +08:00
    这是我测试文件


    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>

    <body>
    测试
    </body>
    </html>
    yuzo555
        12
    yuzo555  
       2020-09-23 15:28:06 +08:00
    Content-Disposition
    YuxiangLuo
        13
    YuxiangLuo  
       2020-09-23 15:29:41 +08:00
    @duanzs 没法下载,你们公司的云存储服务器默认你的每个请求都是下载请求,不给你解析网页的机会。它会给每个 http 响应加上 Content-Disposition,所以你没法下载。
    lxk11153
        14
    lxk11153  
       2020-09-23 15:30:02 +08:00
    @duanzs #10 你看#7,你自己的响应头里带了 Content-Disposition: attachment,所以就下载了;移除它就是浏览器解析了
    duanzs
        15
    duanzs  
    OP
       2020-09-23 15:30:51 +08:00
    @YuxiangLuo 即便是没加这个,我也不能进行网络请求是把
    lxk11153
        16
    lxk11153  
       2020-09-23 15:33:48 +08:00
    @duanzs #8 你在哪里哦,为啥 404 了

    ----
    就是#13 楼说的: 云存储服务器 你的每个请求都是下载请求,不给你解析网页的机会
    duanzs
        17
    duanzs  
    OP
       2020-09-23 15:36:58 +08:00
    @lxk11153 没有“Content-Disposition: attachment”,是不是也不能进行网络请求
    lxk11153
        18
    lxk11153  
       2020-09-23 15:41:26 +08:00
    @duanzs #17 可以网络请求的呀,这个又不是必填响应头
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4929 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.