private string QueryPublic(string a_sMethod, string props = null) { string address = string.Format("{0}/{1}/public/{2}", this.BaseURL, this.Version, a_sMethod); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(address); webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Method = "POST"; AntiFlood.Synchronize(); if (props != null) { using (var writer = new StreamWriter(webRequest.GetRequestStream())) { writer.Write(props); } } //Make the request try { using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream str = webResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(str)) { return(Streams.ToString(sr)); } } } } catch (WebException wex) { using (HttpWebResponse response = (HttpWebResponse)wex.Response) { using (Stream str = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(str)) { if (response.StatusCode != HttpStatusCode.InternalServerError) { throw; } return(Streams.ToString(sr)); } } } } }
private string QueryPrivate(string a_sMethod, string props = null) { if (props.IsNullOrWhiteSpace()) { props = null; } // generate a 64 bit nonce using a timestamp at tick resolution Int64 nonce = DateTime.Now.Ticks; props = "nonce=" + nonce + props; string path = string.Format("/{0}/private/{1}", this.Version, a_sMethod); string address = this.BaseURL + path; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(address); webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Method = "POST"; webRequest.Headers.Add("API-Key", this.APIKey); byte[] base64DecodedSecred = System.Convert.FromBase64String(this.PrivateKey); var np = nonce + System.Convert.ToChar(0) + props; var pathBytes = Encoding.UTF8.GetBytes(path); var hash256Bytes = sha256_hash(np); var z = new byte[pathBytes.Count() + hash256Bytes.Count()]; pathBytes.CopyTo(z, 0); hash256Bytes.CopyTo(z, pathBytes.Count()); var signature = getHash(base64DecodedSecred, z); webRequest.Headers.Add("API-Sign", System.Convert.ToBase64String(signature)); if (props != null) { using (var writer = new StreamWriter(webRequest.GetRequestStream())) { writer.Write(props); } } AntiFlood.Synchronize(); //Make the request try { using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream str = webResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(str)) { return(Streams.ToString(sr)); } } } } catch (WebException wex) { using (HttpWebResponse response = (HttpWebResponse)wex.Response) { using (Stream str = response.GetResponseStream()) { using (StreamReader sr = new StreamReader(str)) { if (response.StatusCode != HttpStatusCode.InternalServerError) { throw; } return(Streams.ToString(sr)); } } } } }