json - 创建以 JSON 对象为标头的 URL
问题描述
我正在探索 Bitso API(Bitso 是一个墨西哥加密货币交易所)。
API 的文档在 Python 和 Ruby 等一些语言中得到了很好的解释,供其使用。这里的问题是没有使用直接 URL 进行请求的示例。
我打算做的是创建代码在其请求函数上创建的 URL。
有一个余额帐户请求,这是我想要获得的数据。根据文档,这是一个私有请求,在请求中需要一些标头(密钥、随机数和签名),您可以在这里查看。
在 Python 中发出此请求的代码如下:
import time
import hmac
import hashlib
import requests
bitso_key = "BITSO_KEY"
bitso_secret = "BITSO_SECRET"
nonce = str(int(round(time.time() * 1000)))
http_method = "GET"
request_path = "/v3/balance/"
json_payload = ""
# Create signature
message = nonce+http_method+request_path+json_payload
signature = hmac.new(bitso_secret.encode('utf-8'),
message.encode('utf-8'),
hashlib.sha256).hexdigest()
# Build the auth header
auth_header = 'Bitso %s:%s:%s' % (bitso_key, nonce, signature)
# Send request
response = requests.get("https://api.bitso.com/v3/balance/", headers={"Authorization": auth_header})
print(response.content)
因此,基于此,我可以说 URL 是这样的:
https://api.bitso.com/v3/balance/Bitso%20<Key>:<nonce>:<signature>
我确定我的假设是错误的,我知道这headers={"Authorization": auth_header}
似乎是一个 JSON 对象,用作 URL 中的标头,但我想知道该 JSON 对象是如何在 URL 处翻译以发出请求的。我想在浏览器上复制粘贴该 URL 并获取数据作为响应。
我需要该 URL,以便可以使用它将服务连接到商业智能工具。
谢谢!
解决方案
According to the documentation this Authorization is a header in the request. You can try using postman but you still need hash the destination URL with your api key and the nonce to avoid replay attacks.
推荐阅读
- regex - Travis 条件部署:使用正则表达式部署脚本以跳过错误“不允许分支”
- google-cloud-firestore - Cloud Function 接收 CSV 并发布到实时数据库
- android - 是否有 RN Number Picker 在 android 上作为轮子工作?
- android - 在 API 级别 29 java 中不推荐使用 Environment.getExternalStorageDirectory()
- flutter - 我的应用程序导航出现错误,同时移动到 2 个以上的屏幕?
- excel - 检查单元格值是否为整数,如果不是则添加消息
- javascript - 我可以使用 javascript map、filter.. 来映射两个具有相同 id 的数组吗?
- python - Keras历史平均自定义损失函数
- laravel - 路由注册前的 Laravel 中间件
- flutter - 一次将一个项目添加到多个列表