As per this code sample, I'm attempting to make a .net httpwebrequest from my local machine to a local bitcoind -daemon server. However, I'm only receiving a 400 bad request at
I am completely stumped as to how to proceed - is there anything obviously wrong with this code? I have the bitcoin.conf file set up with the below username and pass, and it is set to port 8332. These are the ONLY settings I've set in the bitcoin.conf. I'm a noobie in both web requests and the Bitcoin api, so I suspect it's something stupidly obvious.
For a little more information, when I manually navigate to localhost:8332 in the browser, the credentials I use in my program work, and the web page returns:
Here is the code that makes the request:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:8332"); webRequest.Credentials = new NetworkCredential("blah", "blahblah"); /// 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")); // serialize json for the request 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();