Julia HTTP.get() API 密钥授权 [英] Julia HTTP.get() API key Authorization

查看:27
本文介绍了Julia HTTP.get() API 密钥授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问的网站需要 API 密钥 ID 和密钥作为(我假设)基本授权的用户名和密码.

A website I'm accessing requires an API key ID and secret key as the username and password for (I'm assuming) basic authorization.

我正在使用 HTTP 模块中的 HTTP.get 函数,但我找不到如何包含我的密钥 ID 和密钥.

I'm using the HTTP.get function from the HTTP module but I can't find how to include my key ID and secret key.

示例HTTP.get("https://api.mybitx.com/api/1/balance")

这将返回HTTP.StatusError:收到'401 - 未授权'状态作为响应"

and this returns "HTTP.StatusError: received a '401 - Unauthorized' status in response"

该网站有一个 API 指南,但他们提供的唯一帮助是使用 cURL 的示例 $ curl -u keyid:keysecret https://api.mybitx.com/api/1/balance

The website has an API guide but the only help they give is an example using cURL $ curl -u keyid:keysecret https://api.mybitx.com/api/1/balance

我将不胜感激

链接:https://github.com/JuliaWeb/HTTP.jl

推荐答案

API 要求密钥和密码采用以下形式:temp = Basic " + base64encode("your_api_key_here").

The API requires the key and secret code to be in the form: temp = Basic " + base64encode("your_api_key_here").

然后您可以像这样创建一个字典:usr = Dict("Authorization" => temp)

You then create a dictionary like so: usr = Dict("Authorization" => temp)

最后

JSON.parse(String(HTTP.get("https://api.mybitx.com/api/1/balance"; headers = usr)))

JSON.parse(String()) 可能需要更改,因为我上次在相当旧的 Julia 版本上运行代码

The JSON.parse(String()) might need to change as I ran the code on quite an old Julia version last time this worked

这篇关于Julia HTTP.get() API 密钥授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆