javascript - 相同的 URL 提供不同的内容 - 为什么?

标签 javascript url cookies browser content-type

如果您已登录,此 URL:https://download.ama-assn.org/resources/doc/usan/x-pub/usan-february-2014-newsletter.pdf返回 html 页面:

<div id="dlblock">
    <a href="http://www.ama-assn.org">
        <img src="https://www.ama-assn.org/resources/images/header/ama-logo.png" border="0">
    </a><br><br>
    You are about to download<br>
    <strong>
         <a id="file-link" href="/resources/doc/usan/x-pub/usan-february-2014-newsletter.pdf" target="_blank">usan-february-2014-newsletter.pdf</a>
    </strong>
    If you are not automatically redirected, please 
    <a href="/resources/doc/usan/x-pub/usan-february-2014-newsletter.pdf" target="_blank">click here</a> 
    to begin your download.   <br><br>
    <small>Copyright 1995-2014 
        <a href="http://www.ama-assn.org">American Medical Association</a> All rights reserved.
    </small>

如果您点击此页面上的链接(并且该网址与刚刚在新窗口中打开的页面相同),您将获得 pdf 文件。

我不明白服务器如何决定何时提供 html 以及何时提供 pdf - 这是如何实现的?

最佳答案

服务器可能会读取 httpreferer 请求 header ,如果它与页面的 URL 匹配,则提供 PDF 版本。

关于javascript - 相同的 URL 提供不同的内容 - 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22922195/

相关文章:

javascript - 如何使用 jQuery 在循环中获取选中的复选框值?

javascript - 发现 js php 加载/执行问题

javascript - 链接按钮在 JavaScript 中不起作用

android - 使用 GSON 从 URL 解析 JSON

javascript - 如何检查 URL 末尾是否有特定字符串

javascript - Bootstrap 导航栏下拉菜单的问题

javascript - C# Asp.net 必填字段验证器

java - 请求 header 中存在多个 JSESSIONID

c# - 如何从 windows.form 中删除 Cookie?

python - 为什么 cookielib.LWPCookieJar 接受空参数列表?