相同的HTTP GET在第一个请求中具有200个状态,但此后为304

发布于 2025-01-21 19:10:28 字数 1490 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放低过去 2025-01-28 19:10:28

要重塑“ HTTP 304未修改的客户端重定向响应代码表示无需重新发送请求的资源”:

您一次请求资源(来自/profiles的数据),服务器会发送您的服务。该数据具有200 OK状态。现在,当您请求相同的资源(/profiles)及其数据从第一个请求中没有更改时,服务器将使用304未修改的 响应,因为它假设您是您的已经有数据 - 自从请求200 OK以来,它尚未修改。

您说您没有在第一个请求中缓存数据,但是服务器是假设您会(例如 304未修改 的MDN文档,“ 这是对缓存资源的隐含重定向“),并试图节省资源。

您必须确定在您的特定情况下

  • 缓存第一个响应是否最好,
  • 请阅读可能的 到期 标题,并且在那一刻之后才重新召集,或者
  • 可能省略 if-none-match eTAG eTAG header告诉服务器您没有可使用的资源的缓存版本

To rephrase "the HTTP 304 Not Modified client redirection response code indicates that there is no need to retransmit the requested resources":

You request a resource (the data from /profiles) once, and the server sends you that data with a 200 OK status. Now when you request the same resource (/profiles) and its data hasn't changed from the first request, the server will respond with a 304 Not Modified since it assumes you already have the data — it hasn't been modified since the request that was 200 OK.

You say you didn't cache the data in the first request but the server is assuming you would (like the MDN docs for 304 Not Modified say, "It is an implicit redirection to a cached resource") and is trying to save resources.

You'll have to determine if it's best in your specific situation to

  • cache the first response,
  • read a possible Expires header and only rerequest after that moment in time, or
  • possibly omit an If-None-Match ETag header as to tell the server that you don't have a cached version of the resource to use
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文