Hi.. Im hoping someone here knows what i am doing wrong. Some of my calls work, but most return 500, so im confused what is wrong.
I really appreciate the help and feedback.
Here is code that works:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
webRequest.Credentials = new NetworkCredential("bitcoinrpc", "mypassword");
/// important, otherwise the service can't desirialse your request properly
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
JObject joe = new JObject();
joe.Add(new JProperty("jsonrpc", "1.0"));
joe.Add(new JProperty("id", "1"));
joe.Add(new JProperty("method", "listsinceblock"));
JArray props = new JArray();
if (_lastBlock != "")
{
props.Add(_lastBlock);
}
joe.Add(new JProperty("params", props));
string s = JsonConvert.SerializeObject(joe);
byte[] byteArray = Encoding.UTF8.GetBytes(s);
webRequest.ContentLength = byteArray.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse webResponse = webRequest.GetResponse();
Basically, im looping and calling this to find new transactions that I am receiving.
However, when I go to send a transaction out:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");
webRequest.Credentials = new NetworkCredential("bitcoinrpc", "mypassword");
/// important, otherwise the service can't desirialse your request properly
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
JObject joe = new JObject();
joe.Add(new JProperty("jsonrpc", "1.0"));
joe.Add(new JProperty("id", "1"));
joe.Add(new JProperty("method", "sendtoaddress"));
JArray props = new JArray();
props.Add("1diceDCd27Cc22HV3qPNZKwGnZ8QwhLTc");
props.Add("0.001");
joe.Add(new JProperty("params", props));
string s = JsonConvert.SerializeObject(joe);
byte[] byteArray = Encoding.UTF8.GetBytes(s);
webRequest.ContentLength = byteArray.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse webResponse = webRequest.GetResponse();
I get a 500 error.. can anyone tell me what I am doing wrong? I am able to make the call from the commandline with no problem. I'm stumped and can't find any help anywhere on what could be wrong.
Thanks!
Kingsfan