我正在尝试完成信息请求。遵循了 api 的所有说明,但仍然得到 404。
我想执行来自 TradeApi getInfo 的请求。POST https://yobit.net/tapi/getInfo?nonce=1 标头:密钥:{api public key} 签名:{string "?nonce=1" 通过 HMAC-SHA512 用私钥编码}
响应总是 404。怎么了?
我附上代码。要求:
public APIResponse Request(string method, Dictionary<string, string> param = null, int ReRequestCount = 3)
{
lock (locker)
nonce = IncrementNonce();
string urlParamStr = "?";
using (HttpRequest request = new HttpRequest())
{
if (param != null)
foreach (KeyValuePair<string, string> pair in param)
{
request.AddUrlParam(pair.Key, pair.Value);
urlParamStr += pair.Key + "=" + pair.Value + "&";
}
request.AddUrlParam("nonce", nonce);
urlParamStr += "nonce=" + nonce;
string signedData = Get_HMAC_SHA512_Hash(Sign, urlParamStr);
request.AddHeader("Key", Key);
request.AddHeader("Sign", signedData);
HttpResponse response = request.Post("https://yobit.net/tapi/" + method.ToString());
if (response.StatusCode != HttpStatusCode.OK)
{
if (ReRequestCount > 0)
{
return Request(method, param, --ReRequestCount);
}
else
{
return null;
}
}
else
{
return JsonConvert.DeserializeObject<APIResponse>(response.ToString());
}
}
}
HMAC 生成器:
public string Get_HMAC_SHA512_Hash(string key, string source)
{
byte[] secretkeyBytes = Encoding.UTF8.GetBytes(key);
byte[] inputBytes = Encoding.UTF8.GetBytes(source);
using (var hmac = new HMACSHA512(secretkeyBytes))
{
byte[] hashValue = hmac.ComputeHash(inputBytes);
string s = "";
for (int i = 0; i < hashValue.Length; i++)
{
s += string.Format("{0:x2}", hashValue[i]);
}
return s;
//return System.Convert.ToBase64String(hashValue);
}
}
API 应该这样调用:
https://yobit.net/tapi?method=getInfo&nonce=1