{
string parameters = $"method=getInfo&nonce=" + (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
string address = $"{tapi}/";
var keyByte = Encoding.UTF8.GetBytes(secret);
string sign1 = string.Empty;
byte[] inputBytes = Encoding.UTF8.GetBytes(parameters);
using (var hmac = new HMACSHA512(keyByte))
{
byte[] hashValue = hmac.ComputeHash(inputBytes);
StringBuilder hex1 = new StringBuilder(hashValue.Length * 2);
foreach (byte b in hashValue)
{
hex1.AppendFormat("{0:x2}", b);
}
sign1 = hex1.ToString();
}
WebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(address);
if (webRequest != null)
{
webRequest.Method = "POST";
webRequest.Timeout = 20000;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Headers.Add("Key", key);
webRequest.Headers.Add("Sign", sign1);
webRequest.ContentLength = parameters.Length;
using (var dataStream = webRequest.GetRequestStream())
{
dataStream.Write(inputBytes, 0, parameters.Length);
}
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
{
var jsonResponse = sr.ReadToEnd();
Console.WriteLine(String.Format("Response: {0}", jsonResponse));
}
}
}
}