我正在尝试在UWP平台上向yobit api发帖请求,这些代码适用于其他平台。这是我的代码 -
public async Task<RootObject> sellLimitCode()
{
RootObject track = null;
try
{
string url = "https://yobit.net/tapi/";
string parameters = "method=Trade&pair=ltc_btc&type=buy&rate=1&amount=1&nonce=" + (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
String strMsg = "api secret";
var uriBytes = encoding.GetBytes(parameters);
var uriBytes1 = encoding.GetBytes(strMsg);
string str_alg_name = MacAlgorithmNames.HmacSha512;
MacAlgorithmProvider obj_mac_prov = MacAlgorithmProvider.OpenAlgorithm(str_alg_name);
IBuffer buff_msg = CryptographicBuffer.CreateFromByteArray(uriBytes);
IBuffer buff_key_material = CryptographicBuffer.CreateFromByteArray(uriBytes1);
CryptographicKey hmac_key = obj_mac_prov.CreateKey(buff_key_material);
IBuffer hmac = CryptographicEngine.Sign(hmac_key, buff_msg);
byte[] digest = hmac.ToArray();
string hashText = byteToString(digest);
StringBuilder hex1 = new StringBuilder(hashText.Length * 2);
foreach (byte b in digest)
{
hex1.AppendFormat("{0:x2}", b);
}
string sign1 = hex1.ToString();
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "POST";
httpWebRequest.Headers["Key"] = "api key";
httpWebRequest.Headers["Sign"] = sign1;
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
var httpResponse = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
catch (Exception ex)
{ }
return track;
}
但我获得了成功:0,无效的密钥,方法或nonce。我尝试过更改所有内容。但仍无法正常工作。