javascript - 使用 Javascript 向 ProBasketballAPI.com 发出 POST 请求
问题描述
我正在尝试从 ProBasketballAPI.com API 获取数据。文档说明以下内容:
'要调用 ProBasketball API,您必须向指定的 URL 发出 POST 请求。在这个请求中,您必须传递您的 API 密钥,就是这样。您现在可以访问 API!
当然,您可以传递参数,而不仅仅是您的 API 密钥,事实上,鼓励您这样做。这将有助于缩小将返回的数据范围。
所有响应都将采用 JSON 格式。
我试图将 api_key 作为参数传递,因为它是这样声明的。
const options = {
'api_key': JSON.stringify(api_key),
method: 'post',
headers: {
'Content-Type': 'application/json'
}
};
const x = fetch('https://probasketballapi.com/players', options);
x.then((response) => {
const data = response.json();
data.then((response) => {
console.log(response)
})
})
但我从 api 收到以下错误,
{ errors: [ 'The api key field is required.' ] }
我已经阅读了文档,但我无法弄清楚。该文档可在https://probasketballapi.com/docs/authentication
解决方案
推荐阅读
- xamarin - Xamarin.forms plugin.FingerPrint 无法添加到我的项目中
- javascript - JS跳过名称中两部分代码之间的差异
- python - 用 Python 编写的带有 SPIKE 的模糊测试服务器
- ip - iceccd 输出:错误:地址已在使用中
- python - 如何从 div 类下获取 a href 链接?
- openid-connect - 没有为 OIDC 安全方案填充 swagger-ui 上的可用授权模式
- javascript - 滚动到顶部到原始滚动状态
- jquery - 调用所有类方法或函数的 JQuery 侦听器
- xamarin.android - 图像的长度和宽度是两倍,为什么?
- java - Java Flight Recorder - 没有活动对象