简体   繁体   English

当服务器永不停止加载时,如何在 JavaScript 中存储来自 get 请求的初始文本/事件流响应?

[英]How can I store the initial text/event-stream response from a get request in JavaScript when the server never stops loading?

I'm trying to retrieve some simple values from an API.我正在尝试从 API 中检索一些简单的值。 This is the request URL:这是请求网址:

https://pool.rplant.xyz/api2/poolminer2x/raptoreum/RThRfoQJg8qsoStLk7QdThQGmpbFUCtvnk/UlRoUmZvUUpnOHFzb1N0TGs3UWRUaFFHbXBiRlVDdHZua3x4 https://pool.rplant.xyz/api2/poolminer2x/raptoreum/RThRfoQJg8qsoStLk7QdThQGmpbFUCtvnk/UlRoUmZvUUpnOHFzb1N0TGs3UWRUaFFHbXBiRlVDdHZua3x4

It seems that somehow the server puts the page in a constant refresh state.似乎服务器以某种方式将页面置于持续刷新状态。 Whether in the browser or via my code, loading never completes, but I can see the JSON response in the browser.无论是在浏览器中还是通过我的代码,加载永远不会完成,但我可以在浏览器中看到 JSON 响应。 After about a minute, another JSON response is appended to the original in the browser.大约一分钟后,另一个 JSON 响应会附加到浏览器中的原始响应。

This is the code snippet I'm currently using, and it doesn't seem to ever terminate although I've only waited a max of amount 5 minutes.这是我目前使用的代码片段,虽然我最多只等了 5 分钟,但它似乎永远不会终止。

var response = UrlFetchApp.fetch("https://pool.rplant.xyz/api2/poolminer2x/raptoreum/RThRfoQJg8qsoStLk7QdThQGmpbFUCtvnk/UlRoUmZvUUpnOHFzb1N0TGs3UWRUaFFHbXBiRlVDdHZua3x4")
var json = JSON.parse(response.getContentText())

Is there a way for me to terminate the never-ending loop and retrieve what I already have as a response?有没有办法让我终止永无止境的循环并检索我已经拥有的作为响应?

Edit:编辑:

As @JeremyThille pointed out, the response type is text/event-stream but am still unsure of who to handle this type of response.正如@JeremyThille 指出的那样,响应类型是text/event-stream但我仍然不确定谁来处理这种类型的响应。

Looks like the proper way to handle text/event-stream responses is usually with EventSource however, I am unable to use external libraries for my use case in Google Sheets.看起来处理text/event-stream响应的正确方法通常是使用EventSource但是,我无法在 Google Sheets 中为我的用例使用外部库。

var source = new EventSource('https://pool.rplant.xyz/api2/poolminer2x/raptoreum/RThRfoQJg8qsoStLk7QdThQGmpbFUCtvnk/UlRoUmZvUUpnOHFzb1N0TGs3UWRUaFFHbXBiRlVDdHZua3x4');
source.addEventListener('message', function(e) {
  console.log(e.data);
}, false);

暂无
暂无

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

相关问题 有没有办法在不使用事件侦听器的情况下从文本/事件流中获得单个响应? - Is there a way to get a single response from a text/event-stream without using event listeners? 服务器发送的事件不是“文本/事件流” - Server Sent Events are not “text/event-stream” 是否可以在 WebBrowser 中使用 JavaScript 使用文本/事件流? - Is it possible to consume text/event-stream with JavaScript in a WebBrowser? 如何从express.js发送“文本/事件流”数据? - How to send 'text/event-stream' data from express.js? EventSource的响应具有不是“ text / event-stream”的MIME类型(“ text / html”) - EventSource's response has a MIME type (“text/html”) that is not “text/event-stream” EventSource 的响应具有不是“text/event-stream”的 MIME 类型(“text/html”)。 中止连接。 标头设置为文本/事件流 - EventSource's response has a MIME type ("text/html") that is not "text/event-stream". Aborting the connection. header is set to text/event-stream EventSource的响应具有MIME类型(“text / plain”),而不是“text / event-stream” - EventSource's response has a MIME type (“text/plain”) that is not “text/event-stream” Express NodeJS 路由错误文本/html 不是文本/事件流 - Express NodeJS Routing Error text/html is not text/event-stream 如何为表单中的文本字段设置初始值? 此值是从javascript函数生成的。 没有botton的情况下如何定义事件? - How to set a initial value for a text field in a form? This value is generated from a javascript function. How can i define the event without botton? 客户端javascript:不允许使用CORS时,如何获取HTTP请求的响应标头? - Client-side javascript: how can I get the response header of a HTTP request when CORS is not allowed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM