我在調用MTGox HTTP API P2時遇到了問題。 我寫了一個sendrequest函數來處理所有的請求。 它適用於MONEY/INFO或MONEY/ORDERS,但當我嘗試方法MONEY/ORDER/QUOTE或MONEY/ORDER/ADD時,會出現500內部服務器錯誤。使用MTGOX API的內部服務器
它似乎是當post_data包含除nonce以外的任何東西時,它會出錯。 我需要做些什麼來解決這個問題?
sendRequest函數也:
private string sendRequest(string action, NameValueCollection query)
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("nonce", DateTime.Now.Ticks.ToString());
nvc.Add(query);
String post_data = "";
for (int i = 0; i < nvc.Count; i++)
{
post_data += "&";
post_data += nvc.Keys[i];
post_data += "=";
post_data += nvc[i];
}
post_data = post_data.Substring(1);
action = "BTCEUR/money/" + action;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sBasePath + action);
action += "\0"+post_data;
req.Method = "POST";
HMACSHA512 hmac = new HMACSHA512(GetBytes(action));
hmac.Key = Convert.FromBase64String(secret);
String sign = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(action)), Base64FormattingOptions.None);
req.Headers.Add("Rest-Key", apikey);
req.Headers.Add("Rest-Sign", sign);
req.UserAgent = "Mozilla/4.0 (compatible; MtGoxTradeCLI)";
req.ContentType = "application/x-www-form-urlencoded";
StreamWriter reqStream = new StreamWriter(req.GetRequestStream());
reqStream.Write(post_data);
reqStream.Close();
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader respStream = new StreamReader(resp.GetResponseStream());
String response = respStream.ReadToEnd();
respStream.Close();
return response;
}
感謝您的回答。但不幸的是,它並沒有幫助我。 我試着改變參數順序,以使nonce最後一次,嘗試BTCEUR/money/...和money/...,創建一個新的API密鑰,但仍然得到500內部服務器錯誤。 我的其他API調用仍然可以與您提到的幾點不同。 – 2013-04-24 09:26:00