首页 > 解决方案 > 创建以 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,以便可以使用它将服务连接到商业智能工具。

谢谢!

标签: jsonurlget

解决方案


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.


推荐阅读