<p>As per <a href="https://en.bitcoin.it/wiki/Running_Bitcoin#Command-line_arguments" rel="nofollow">this code sample</a>, 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 <code>webRequest.GetResponse()</code>. </p>

<p>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.</p>

<p>For a little more information, when I manually navigate to localhost:8332 <strong>in the browser</strong>, the credentials I use in my program work, and the web page returns:</p>

<pre><code>{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}
</code></pre>

<p>Here is the code that makes the request:</p>

<pre><code>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();
</code></pre>

CC BY-SA 3.0
2013-04-01T08:27:10.633Z
I'm reading the bitcoin source, and there are [a few things](https://github.com/bitcoin/bitcoin/blob/master/src/bitcoinrpc.cpp#L896) that can cause the rpc service to come back with error 400. Could you post the full response text that your program gets?
Nick ODell
CC BY-SA 3.0
2013-04-02T11:59:15.253Z
As far as I can see, you aren't actually calling a method. Duplicating your request as best I can with curl (curl --user user --data-binary '{"jsonrpc": "1.0"}' http://127.0.0.1:8332/) gets me a "Missing method" error, which could be your problem, though I'm not remotely familiar with the Json.Net library.
BinaryMage
<bitcoind><api><c#>
bitcoind 400 bad request - what's wrong with this code?
valen
# bitcoind 400 bad request - what's wrong with this code?

(Asked by: username_0 on 2013-04-01)

As per [this code sample](https://en.bitcoin.it/wiki/Running_Bitcoin#Command-line_arguments), 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 `webRequest.GetResponse()`.

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:

```
{"result":null,"error":{"code":-32700,"message":"Parse error"},"id":null}

```

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();

```

**Tags:** bitcoind, api, c#

> **Comments:**
> **username_1**: I'm reading the bitcoin source, and there are [a few things](https://github.com/bitcoin/bitcoin/blob/master/src/bitcoinrpc.cpp#L896) that can cause the rpc service to come back with error 400. Could you post the full response text that your program gets?  
> **username_2**: As far as I can see, you aren't actually calling a method. Duplicating your request as best I can with curl (curl --user user --data-binary '{"jsonrpc": "1.0"}' http://127.0.0.1:8332/) gets me a "Missing method" error, which could be your problem, though I'm not remotely familiar with the Json.Net library.  

---

## 0 answers

