在这种情况下,“对服务器的两次请求”的实际含义是什么? [英] What's the actual meaning of 'two requests to the server' in this context?

查看:85
本文介绍了在这种情况下,“对服务器的两次请求”的实际含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在w3schools.com的 HTML链接章节上学习HTML教程时,我看到以下内容句子:


如果子文件夹地址没有正斜杠,则可能会向服务器生成两个请求。许多服务器会自动向地址添加正斜杠,然后创建一个新请求。


我没有得到如果在锚标签的href属性中提到的URL中缺少尾部斜线,那么可以传递两个请求?

一个web服务器接收到 / foo 的请求可能会查看它,并发现它的 foo 实际上是一个文件夹,并且决定该文件夹的 地址是 / foo / 。所以它会以 302 重定向到客户端并告诉它取回 / foo / 代替:


  1. 浏览器到服务器: GET / foo

  2. 服务器到浏览器: 302找到,位置:/ foo /

  3. 浏览器到服务器: GET / foo /

  4. 服务器到浏览器: 200好的,内容...

服务器是否执行此操作取决于您的服务器。最终,您应该始终在链接中使用实际URL 项,不要依赖服务器为您隐式修复它。

While studying HTML tutorial on HTML Links Chapter on w3schools.com I saw following sentence:

Without a forward slash on subfolder addresses, you might generate two requests to the server. Many servers will automatically add a forward slash to the address, and then create a new request.

I didn't get the meaning of how two request can be passed if trailing slash is missing in the URL mentioned in href attribute of anchor tag?

解决方案

A web server receiving a request for /foo may look at it and see that its foo is actually a folder, and decide that the actual address for this folder is /foo/. So it will respond with a 302 redirect to the client and tell it to fetch /foo/ instead:

  1. browser to server: GET /foo
  2. server to browser: 302 Found, Location: /foo/
  3. browser to server: GET /foo/
  4. server to browser: 200 OK, content...

Whether the server does this or not depends on your server. Ultimately you should always use the actual URL of items in your links, don't rely on a server to "fix it" implicitly for you.

这篇关于在这种情况下,“对服务器的两次请求”的实际含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆