[英]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.