-
Jun 29th, 2017, 04:34 PM
#1
Thread Starter
Lively Member
[RESOLVED] Help converting c# to vb net code
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:
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);
}
}
}
}
}
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.
-
Jun 29th, 2017, 04:50 PM
#2
Re: Help converting c# to vb net code
The reason why it is likely failing when you put it through the converter is because it is implicitly declaring a variable that returns the value from a Function named sha256_hash. Do you have that particular Function declared?
-
Jun 29th, 2017, 04:56 PM
#3
Thread Starter
Lively Member
Re: Help converting c# to vb net code
AH yes silly mistake. I didn't read far enough through that C# example! We can close this out...
-
Jun 29th, 2017, 07:45 PM
#4
Re: Help converting c# to vb net code
Originally Posted by hockeyadc
We can close this out...
Then you should use the Thread Tools menu to mark the thread Resolved.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|