【问题标题】:I want to attach an API key to my URL to give access to the database, the problem is attaching it to the filename我想将 API 密钥附加到我的 URL 以访问数据库,问题是将其附加到文件名
【发布时间】:2021-06-16 15:15:43
【问题描述】:

我想将 API 密钥附加到我的 URL 以授予对数据库的访问权限,问题在于将其附加到文件名

var pivot = new WebDataRocks({
    container: "#wdr-component",
    toolbar: true,
    report: {
        dataSource: {
            filename: "https://testing-195b.restdb.io/rest/customerdata"
        }
    }
});

此代码适用于控制台

  var settings = {
    "async": true,
    "crossDomain": true,
    "url": "https://testing-195b.restdb.io/rest/customerdata",
    "method": "GET",
    "headers": {
      "content-type": "application/json",
      "x-apikey": "60c8b39ee2c96c46a2463581",
      "cache-control": "no-cache"
      
    }
  }
  
  $.ajax(settings).done(function (response) {
    console.log(response);
    
  });

【问题讨论】:

  • 有什么问题?
  • 我正在使用一个名为 restdb.io 的数据库,生成了一个网页 API 密钥 (CORS),如果要访问我的数据库,我需要它,这里的问题是我使用的是有自己的语法的网络报告工具,我需要找到附加 API 密钥或绕过错误“No 'Access-Control-Allow-Origin”

标签: javascript html backend api-key webdatarocks


【解决方案1】:

如果需要传递请求标头,最好通过从 WebDataRocks 单独发出请求来获取数据。这样它就可以包含所有需要的信息。之后,可以通过以下方式将数据从网页馈送到 WebDataRocks:

var pivot = new WebDataRocks({
    container: "#wdr-component",
    toolbar: true,
    report: {
        dataSource: {
            data: yourData // your variable containing the data
        }
    }
});

【讨论】:

  • 谢谢,能够使用“fetch”来获取和存储数据
【解决方案2】:

您可以像这样将 API 密钥作为 URL 参数传递:

“https://testing-195b.restdb.io/rest/customerdata?apikey=XXXXXXXX”

【讨论】:

  • 感谢贡献,可惜这个方法还是不行,报错:“好像这个文件不存在或者'Access-Control-Allow-Origin'头文件在请求的资源”,仍然出现。
  • 您是否检查过此 API 密钥的 Cors 设置?域和路径必须匹配,但对于测试,您可以使用 /** 表示路径,使用 * 表示域
猜你喜欢
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2022-08-14
  • 1970-01-01
  • 2011-10-11
  • 1970-01-01
  • 1970-01-01
  • 2018-12-20
相关资源
最近更新 更多