GET 请求从随机端点返回相同的信息 [英] GET Request Returning Same Info from a Randomized Endpoint

查看:39
本文介绍了GET 请求从随机端点返回相同的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问 QuotesOnDesign 随机端点:https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1& 和一些原因我每次都得到相同的值,即使启用了无缓存.这发生在每个浏览器和 Postman 中.

I'm accessing the QuotesOnDesign randomized endpoint: https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1& and for some reason I'm getting the same value returned everytime, even with no-cache enabled. This happens in every browser and in Postman.

不,想知道我能做些什么来解决这个问题,因为它在几周前才真正起作用.我最后一次提交是在 6 月底,当时一切正常.

No, idea what I can do to fix this, as it was working literally just a few weeks ago. My last commit was the end of June and it was working fine then.

我访问端点的函数如下:

My function that accesses the endpoint is as follows:

  httpCallout(){
    fetch('https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&', {cache: "no-cache"})
    .then(response => response.json())
    .then((data) => {
      const quote = data[0].content;
      console.log(quote);
      this.setState({
        quote: quote,
        author: data[0].title
      });
    });
  }

理论上,它每次都应该返回一个新的引用,就像以前一样.但现在,我只是每次都收到相同的数据.

In theory, it should return a new quote every time, as it previously was. But now, I'm simply receiving the same data every time.

推荐答案

网站似乎使用客户端代码来选择某种起始值(可能是随机种子、ID 或页码,或者什么?)开始并将该 ID 包含在请求中(例如 https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_=1564694860977.

It appears that website uses client-side code to pick some kind of a starter value (perhaps a random seed, or an ID, or a page number, or something?) to start with and includes that ID in the request (e.g. https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_=1564694860977).

由于您没有在请求中包含该值,因此它显然使用了默认值,并且每次获得相同结果时它都是相同的值.

Since you're not including that value in your request, it's apparently using a default value, and since it's the same value every time you're getting the same results every time.

这篇关于GET 请求从随机端点返回相同的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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