简体   繁体   English

Angular HTTP'get'请求304错误

[英]Angular HTTP 'get' request 304 error

I was building angular's official 'heroes tutorial app' and instead of using their in-memory-data code, i tried using a json.placeholders (users) api so the app would be more real-world example. 我正在构建angular的官方“英雄教程应用程序”,而不是使用其内存数据代码,而是尝试使用json.placeholders(users)API,因此该应用程序将是更实际的示例。

Problem is when i change the official codes example url(in-memory-url) with the json.placeholder's api it just doesnt list the names and i checked the chrome dev console-network tab it shows status code 304, 问题是,当我使用json.placeholder的api更改官方代码示例url(in-memory-url)时,它只是没有列出名称,并且我检查了chrome dev控制台网络标签,其中显示了状态代码304,

By the way I am only trying to make a get request part of the tutorial, here is the error: 顺便说一下,我只想使获取请求成为本教程的一部分,这是错误:

Request URL:https://jsonplaceholder.typicode.com/users
Request Method:GET
Status Code:304 
Remote Address:104.31.87.157:443
Referrer Policy:no-referrer-when-downgrade

Edit: 编辑:

So i managed to list users from json.placeholder on the app with using observables from rxjs, then i changed it back to promise method official website shows that way and still not listing. 所以我设法使用rxjs的可观察对象从应用程序上的json.placeholder列出用户,然后我将其更改回诺言方法官方网站以这种方式显示,但仍未列出。 Maybe it's something about the angular's promises i dont know. 也许这与我不知道的角度承诺有关。

However browsers network still showing 304 status. 但是,浏览器网络仍显示304状态。 I am worrying that this could be a problem and it shouldn't be this way. 我担心这可能是个问题,而不应该这样。 So any help would be appreciated thanks. 因此,任何帮助将不胜感激谢谢。

HTTP 304 header code means "Not modified", it's not an error. HTTP 304标头代码表示“未修改”,这不是错误。 According to the RFC 2616 of HTTP 1.1, the server only sends back headers, not the response which tells the browser to use the response that it had already in cache. 根据HTTP 1.1的RFC 2616,服务器仅发送回标头,而不发送响应,该响应告诉浏览器使用已在缓存中的响应。

On the other hand, angular will always put 200 in status (even if it is a 304) and you shouldn't have to bother about keeping up to date your data, since you retrieve the fresher value each time (without bothering if it's from a cache in the server or fresh data from the server) 另一方面,角度将始终将200置于状态(即使它是304),您也不必费心保持最新数据,因为您每次都检索较新的值(如果来自服务器中的缓存或服务器中的新数据)

Id Add a random query string behind your url, that takes timestamp as the value. Id在您的网址后面添加一个随机查询字符串,该字符串将时间戳记作为值。 This way, each request will be considered a fresh one 这样,每个请求都将被视为新请求

Moreover id refer you to this topic 此外,id还可以向您介绍该主题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM