Here is my web request code block,
scroll down to the bottom of it to the catch exception
try
{
var webRequest = System.Net.WebRequest.Create (WEBSERVICE_URL);
if (webRequest != null) {
webRequest.Method = "POST";
//webRequest.Timeout = 12000;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Headers.Add ("Key", _apiKey);
webRequest.Headers.Add ("Sign", genHMAC ());
byte[] dataStream = Encoding.UTF8.GetBytes("command=returnBalances&nonce=" + nonce);
webRequest.ContentLength = dataStream.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
using (System.IO.Stream s = webRequest.GetResponse ().GetResponseStream ()) {
using (System.IO.StreamReader sr = new System.IO.StreamReader (s)) {
var jsonResponse = sr.ReadToEnd ();
OutputText.text = jsonResponse.ToString ();
}
}
}
}
catch (Exception ex)
{
OutputText.text = ex.ToString ();
}
This gives me an "error(403) Forbidden" and the exception stack trace, but I am trying to get the 403 Response Body:
I cannot get Unity C# to accept the following code: mentioned here
catch(WebException ex)
{
var response = (HttpWebResponse)ex.Response;
}
What do I need to make this method work? I need the Response body
hmac.ToString()will not generate valid sign. To generate valid sign for Poloniex, you must use HMACSHA512.ComputeHash method and pass itdataStreamas an argument. Bytes returned from this method then must be converted to hexadecimal string.This should generate valid sign:
Regarding WebException, it is declared in
System.Netnamespace, so make sure you haveusing System.Net;. Depending on target framework, WebException shoul be inSystem.Net.Requests.dll,System.dll, ornetstandard.dll. Unfortunatelly I don't have any experience with Unity, but if my guess that it targets ordinary.NET Frameworkis correct, then WebException is declared inSystem.dlland your project should already have reference to it and no additional assembly reference should be needed.