I would like to use the c# code from this API here:
https://bitbucket.org/arrivets/krake...e-view-default
to request the POST data in a VB Net program I have. All I really need converted to VB NET is the code below:
Now, I know I can throw this into a c# to vb net converter, but it doesn't work as well as I planned. I am having some issues with the SHA256 portion.Code:private JsonObject QueryPrivate(string a_sMethod, string 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}", _version, a_sMethod); string address = _url + path; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(address); webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.Method = "POST"; webRequest.Headers.Add("API-Key", _key); byte[] base64DecodedSecred = Convert.FromBase64String(_secret); var np = nonce + 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", Convert.ToBase64String(signature)); if (props != null) { using (var writer = new StreamWriter(webRequest.GetRequestStream())) { writer.Write(props); } } //Make the request try { //Wait for RateGate _rateGate.WaitToProceed(); using (WebResponse webResponse = webRequest.GetResponse()) { using (Stream str = webResponse.GetResponseStream()) { using (StreamReader sr = new StreamReader(str)) { return (JsonObject)JsonConvert.Import(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 (JsonObject)JsonConvert.Import(sr); } } } } }




Reply With Quote
