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

查看:79
本文介绍了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天全站免登陆