25

I'am running Bitcoin-qt 0.8.6.1-beta on Qt 4.8.3 on windows 7 64.

below is my .conf content in %appdata%/bitcoin folder

rpcuser=bitcoinrpc
rpcpassword=ahything
rpcallowip=127.0.0.1
rpcallowip=192.168.*.*
rpcport=9332 
server=1
daemon=0
addnode=69.164.218.197

using curl 7.26.0 (i686-pc-mingw32), I run the following command:

curl --user 'bitcoinrpc' --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:8332

the pc ask for host password.

I have tried the .conf password and also the PC password (which is the one I log into my PC)

I always get error 401 (unauthorized) result.

Can anyone advice me where did I went wrong or how do I know which password it refer to?

TIA

Regards, KK Gian

Gian
  • 376
  • 1
  • 3
  • 5

2 Answers2

22

You can also make a request by explicitly mentioning the username and password in the URI:

http://bitcoinrpc:[email protected]:8332/

Making your request to this address should be sufficient.

So, full command:

curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://bitcoinrpc:[email protected]:8332/
Jonas Schnelli
  • 6,052
  • 1
  • 21
  • 34
Steven Roose
  • 11,841
  • 8
  • 45
  • 73
  • 3
    Keep in mind however that Steven Roose's suggestion won't work if there's an "@" in the password. Also depending on the connection location, the URL may be visible. It is certainly less secure and not suitable for remote system access. –  Jul 15 '15 at 01:53
15

I got it to work by adding the password to the --user value, separated with ":". So the example becomes:

curl --user bitcoinrpc:xxxxxxxxxxxxxxx --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:8332

Where "xxxxxxxxxxxxxxx" is the rpcpassword stored in the .conf file.

Jeroen Flamman
  • 251
  • 2
  • 3
  • 1
    Have you tried ?
    curl --user bitcoinrpc --password xxxxxxxxxxxxxxx --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getinfo","params":[]}' -H 'content-type:text/plain;' http://127.0.0.1:8332
    – szydan Dec 30 '15 at 02:38
  • 1
    curl: option --password: is unknown – e18r Dec 19 '16 at 13:29
  • getinfo is deprecated. Should now be getnetworkinfo, getblockchaininfo or getwalletinfo. – Jonathan Cross Apr 22 '21 at 23:31