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

查看:88
本文介绍了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包含在请求中(例如

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天全站免登陆