jQuery 速度测试.net api

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10022711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:43:30  来源:igfitidea点击:

speedtest.net api

jquerygoogle-chrome-extension

提问by Ruby

I want to make a widget to display the user's most recent speed test results. Does speedtest.net have an api I could use? I tried making an ajax request to http://speedtest.net/csv.php?csv=1&ria=0&s=0but got a cross domain error. I tried an iframe, but that just made it appear in downloads.

我想制作一个小部件来显示用户最近的速度测试结果。speedtest.net 有我可以使用的 api 吗?我尝试向http://speedtest.net/csv.php?csv=1&ria=0&s=0发出 ajax 请求,但出现跨域错误。我尝试了一个 iframe,但这只是让它出现在下载中。

This is going to be in a Google Chrome extension so I can use the chrome api if necessary.

这将在 Google Chrome 扩展程序中,因此我可以在必要时使用 chrome api。

采纳答案by Xenon

speedtest.net is run by Ookla and their Speed Test application. Unfortunately they don't provide any public APIs for speedtest.net which you could use.

speedtest.net 由Ookla 及其速度测试应用程序运行。不幸的是,他们没有为您可以使用的 speedtest.net 提供任何公共 API。

Although I doubt either of these meet your needs, they do provide Speed Test Miniand a hosted reporting solution for their full Speed Test software package(which includes CSV exporting capabilities).

尽管我怀疑其中任何一个都满足您的需求,但它们确实为完整的 Speed Test 软件包(包括 CSV 导出功能)提供了Speed Test Mini托管报告解决方案

The reason you're unable to use AJAX is because Chrome will not allow JavaScript to perform cross-site requests unless the Access-Control-Allow-Originresponse header is set in the response from speedtest.net to permit such a request.

您无法使用 AJAX 的原因是 Chrome 不允许 JavaScript 执行跨站点请求,除非在Access-Control-Allow-Origin来自 speedtest.net的响应中设置了响应标头以允许此类请求。

In a Chrome extension, however, you can allow cross-origin requests by adding the URL to the permissions section of your manifest.jsonfile. For example:

但是,在 Chrome 扩展程序中,您可以通过将 URL 添加到manifest.json文件的权限部分来允许跨源请求。例如:

"permissions": [
  "http://*/"
],

You could then use a bit of jQuery to retrieve the CSV data as a string (see this answer):

然后,您可以使用一些 jQuery 将 CSV 数据作为字符串检索(请参阅此答案):

$.get('http://speedtest.net/csv.php?csv=1&ria=0&s=0', function(data) {
    var csv = new String(data);
    // do stuff with csv
}, dataType='text');

回答by Akash

Try MySpeed.today. It may work out.

试试MySpeed.today。它可能会奏效。

回答by Shawn

Ookla does provide an API

Ookla 确实提供了API

You need to get their API key. They also provide a sample Python script.

您需要获取他们的 API 密钥。他们还提供了一个示例 Python 脚本。

回答by Rob W

You can make cross-origin XMLHttpRequests in a chrome extension, provided thatyou've requested permissions for it.

您可以在 chrome 扩展程序中创建跨源 XMLHttpRequests,前提是您已为其请求权限。

In your manifest.jsonfile, add the URI:

在您的manifest.json文件中,添加 URI:

"permissions": ["http://speedtest.net/csv.php?*"]

See also: Match patterns.

另请参阅:匹配模式