Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有MTGOX api的内部服务器_C#_Api_Httpwebrequest_Hmac_Bitcoin - Fatal编程技术网

C# 具有MTGOX api的内部服务器

C# 具有MTGOX api的内部服务器,c#,api,httpwebrequest,hmac,bitcoin,C#,Api,Httpwebrequest,Hmac,Bitcoin,调用MTGox HTTP api v2时出现问题。 我编写了一个sendrequest函数来处理所有请求。 它适用于MONEY/INFO或MONEY/ORDERS,但当我尝试MONEY/ORDER/QUOTE或MONEY/ORDER/ADD方法时,会出现500个内部服务器错误 似乎当post_数据包含除nonce之外的任何内容时,就会出错。 我要怎么做才能解决这个问题 sendrequest功能: private string sendRequest(string action, NameVal

调用MTGox HTTP api v2时出现问题。 我编写了一个sendrequest函数来处理所有请求。 它适用于MONEY/INFO或MONEY/ORDERS,但当我尝试MONEY/ORDER/QUOTE或MONEY/ORDER/ADD方法时,会出现500个内部服务器错误

似乎当post_数据包含除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;
    }
私有字符串sendRequest(字符串操作、NameValueCollection查询)
{
NameValueCollection nvc=新的NameValueCollection();
Add(“nonce”,DateTime.Now.Ticks.ToString());
添加(查询);
字符串post_data=“”;
对于(int i=0;i
对于任何带有参数的请求,请确保签名中的nonce位于签名的最后,例如,对于货币为美元的金钱/钱包/历史记录,您的签名应为:

money/wallet/history\0currency=USD&nonce=xxxxxxxxxx
(0是空字符,以防万一)

此外,MtGox的API目前似乎在不断变化——例如,对于上面的钱包历史记录,我们通常称之为:

BTCUSD/money/wallet/history
作为API端点,但这似乎不再有效。现在我们呼吁:

money/wallet/history
所以,如果以前为你工作的电话现在失败了,也看看这个。但我可以肯定地告诉您,将nonce作为QS中签名的最后一个参数是至关重要的,否则API调用将不再有效


我还建议在MtGox中重新创建一个新的API密钥——我们必须这样做才能使代码正常工作。我有一种预感,这是因为MtGox最近的API更改使旧密钥无效(可能会阻止交易机器人,而他们知道如何处理它们而不会让机器人杀死它们的API)

感谢您的回答。但不幸的是,这对我没有帮助。我尝试更改参数顺序,使nonce最后出现,尝试了BTCEUR/money/。。。和money/…,创建了一个新的API密钥,但仍然得到一个500内部服务器错误。除了您提到的几点之外,我的其他API调用仍然有效。