我尝试在 C# 中恢复有关 bittrex 交换平台上的加密货币的信息。
为此,我有这个网站:https ://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC 。使用 Chrome 我有这个结果:
{"success":true,"message":"","result":"Bid":0.01678600,"Ask":0.01680095,"Last":0.01678600}}
我想恢复它。所以在我的表格中我设置:
公共变量:
public const string BaseUrl = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC";
公共按钮事件:
var webreq = WebRequest.Create(BaseUrl);
var webresp = webreq.GetResponse();
MessageBox.Show("" + webresp);
当我运行 then 程序时,我得到一个身份验证问题的错误,但是,我只是何时使用公钥读取信息。
有谁知道我错在哪里?以及如何绕过此身份验证问题?
更新:感谢 Dieter B,我仍然有身份验证错误,我不确定编码和所需的时间格式。你有什么线索吗?
public static string time = DateTime.Now.ToString();
public static string apisecret = "f**********************************d";
public static string BaseUrl = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC?apikey=56************************61a&nonce="+time;
public static readonly Encoding encoding = Encoding.UTF8;
public static string sbinary;
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
var keyByte = encoding.GetBytes(BaseUrl);
using (var hmacsha256 = new HMACSHA256(keyByte))
{
hmacsha256.ComputeHash(encoding.GetBytes(apisecret));
sbinary = ByteToString(hmacsha256.Hash);
}
HttpWebRequest GETRequest = (HttpWebRequest)WebRequest.Create(BaseUrl);
GETRequest.Headers.Add("apisign", sbinary);
GETRequest.Method = "GET";
MessageBox.Show(sbinary);
HttpWebResponse GETResponse = (HttpWebResponse)GETRequest.GetResponse();
Stream GETResponseStream = GETResponse.GetResponseStream();
StreamReader sr = new StreamReader(GETResponseStream);
MessageBox.Show(sr.ReadToEnd());
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
sbinary += buff[i].ToString("X2"); /* hex format */
return sbinary;
}
谢谢