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

2020-09-23 15:05:01 +08:00
 duanzs

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

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

3509 次点击
所在节点    HTML
18 条回复
songjiaxin2008
2020-09-23 15:07:06 +08:00
liyang5945
2020-09-23 15:07:33 +08:00
HTTP content-type
duanzs
2020-09-23 15:07:57 +08:00
自问自答一下:有可能是协议不同,放在服务器上走的是 http,放在存储上走的是 file 协议,具体我就不懂了,欢迎大佬补充?
duanzs
2020-09-23 15:14:36 +08:00
@liyang5945
@songjiaxin2008
两位大佬,content-type 这个东西不是请求相关的吗,跟本身文件有关系?
Tink
2020-09-23 15:17:11 +08:00
跟协议没啥关系,都是 http,楼上两位已经说清楚了
Content-Type:text/html ;
lxk11153
2020-09-23 15:20:31 +08:00
你看看区别在哪: curl -I 'https://xhgxa.ml/index.html'
duanzs
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
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
2020-09-23 15:22:39 +08:00
duanzs
2020-09-23 15:24:59 +08:00
@YuxiangLuo 我不是要下载这个文件,我想打开这个文件
duanzs
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
2020-09-23 15:28:06 +08:00
Content-Disposition
YuxiangLuo
2020-09-23 15:29:41 +08:00
@duanzs 没法下载,你们公司的云存储服务器默认你的每个请求都是下载请求,不给你解析网页的机会。它会给每个 http 响应加上 Content-Disposition,所以你没法下载。
lxk11153
2020-09-23 15:30:02 +08:00
@duanzs #10 你看#7,你自己的响应头里带了 Content-Disposition: attachment,所以就下载了;移除它就是浏览器解析了
duanzs
2020-09-23 15:30:51 +08:00
@YuxiangLuo 即便是没加这个,我也不能进行网络请求是把
lxk11153
2020-09-23 15:33:48 +08:00
@duanzs #8 你在哪里哦,为啥 404 了

----
就是#13 楼说的: 云存储服务器 你的每个请求都是下载请求,不给你解析网页的机会
duanzs
2020-09-23 15:36:58 +08:00
@lxk11153 没有“Content-Disposition: attachment”,是不是也不能进行网络请求
lxk11153
2020-09-23 15:41:26 +08:00
@duanzs #17 可以网络请求的呀,这个又不是必填响应头

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709781

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX