Author

Topic: Cryptsy API (Read 1321 times)

sr. member
Activity: 252
Merit: 250
January 08, 2014, 10:36:15 AM
#1
So, i'm trying to talk to the cryptsy API using C#.
So far i've been able to talk to it, however it still gives me an error:
{"success":"0","error":"Unable to Authorize Request - Check Your Post Data"}

Looking into the PHP on the crytsy page, and the python here i have tried to copy that using the C# components.
However, still no success.

Anyone else who has an idea?

Code:
            Encoding encoding = Encoding.UTF8;
           
            string par = "method=allmyorders&nonce=" + GetUnixTimestamp(DateTime.Now).ToString();

            Uri url = new Uri(_APIUrl).AddQuery("method", "allmyorders");

            byte[] parBytes = encoding.GetBytes(par);
            var keyByte = encoding.GetBytes(_PrivateKey + par);

            var hmac = new HMACSHA512(keyByte);
            string finalpass = BitConverter.ToString(hmac.Key, 0).Replace("-", "");

            //var KeyByte = encoding.GetBytes(_PrivateKey);
            //var hmacsha512 = new HMACSHA512(KeyByte);
            //var messagebytes = encoding.GetBytes(par);

            //var hash = hmacsha512.ComputeHash(messagebytes);
           
            WebRequest request = WebRequest.Create(url);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
           
            request.Credentials = new NetworkCredential(_PublicKey, finalpass);

            try
            {

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream stream = response.GetResponseStream();

                string strpage2check;
                using (StreamReader sr = new StreamReader(stream))
                {
                    strpage2check = sr.ReadToEnd();
                }

                int y = 1;
            }
            catch (WebException ex)
            {
                HttpWebResponse ErrorResp = (HttpWebResponse)ex.Response;
                if (ErrorResp.StatusCode == HttpStatusCode.NotFound)
                {
                    int x = 9;
                }
            }
Jump to: