12

I started geth on a remote server running on rinkeby with the parameters --rinkeby --fast --cache=128 --rpc --rpcaddr 0.0.0.0

When I try to test my access to geth using

curl -X POST --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://my-geth-remote-server:8545

I received the response

invalid content type, only application/json is supported

Pretty confused about the error, isnt the RPC payload given in JSON already?

Geth used is Geth/v1.7.3-unstable-9b97f983/linux-amd64/go1.9.2

Response of curl after adding -v

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":42}' http://8.8.8.8:8545 -v

* Rebuilt URL to: http://8.8.8.8:8545/
* timeout on name lookup is not supported
*   Trying 8.8.8.8...
* TCP_NODELAY set
* Connected to 8.8.8.8 (8.8.8.8) port 8545 (#0)
> POST / HTTP/1.1
> Host: 8.8.8.8:8545
> User-Agent: curl/7.55.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 57
>
* upload completely sent off: 57 out of 57 bytes
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Mon, 13 Nov 2017 21:39:48 GMT
< Content-Length: 109
<
{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid character '\\'' looking for beginning of value"}}
* Connection #0 to host 8.8.8.8 left intact

curl --version

curl 7.55.0 (x86_64-w64-mingw32) libcurl/7.55.0 OpenSSL/1.0.2l zlib/1.2.11 libssh2/1.8.0 nghttp2/1.23.1
Release-Date: 2017-08-09
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz TLS-SRP HTTP2 HTTPS-proxy Metalink

This is the windows versions of curl.

5
  • 2
    add -H "Content-Type: application/json" Nov 13, 2017 at 21:30
  • may be helpful to also show us what your curl version is. curl --version Nov 13, 2017 at 21:45
  • @LibertyLocked Updated question with details... its a windows version of curl, my macbook is currently down Nov 13, 2017 at 21:52
  • I'm guessing you're using curl.exe on Windows and is having issues with quotes. See this related SO question Nov 13, 2017 at 21:52
  • @LibertyLocked Yes! This command works now curl -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"params\":[],\"id\":42}" http://8.8.8.8:8545 Nov 13, 2017 at 21:56

3 Answers 3

20

According to the Geth JSON RPC docs

The curl options below might return a response where the node complains about the content type, this is because the --data option sets the content type to application/x-www-form-urlencoded . If your node does complain, manually set the header by placing -H "Content-Type: application/json" at the start of the call.

You should add -H "Content-Type: application/json" if you get a content type complaint.

So your request should be

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":42}' http://myserver.com:8545

If you use curl.exe on Windows you have to escape all the double quotes

curl -H "Content-Type: application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"web3_clientVersion\",\"pa‌​rams\":[],\"id\":42}‌​" http://myserver.com:8545
3
  • Got the error {"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid character '\\'' looking for beginning of value"}} Nov 13, 2017 at 21:37
  • You may have other network issues. Try adding a -v and see what comes up Nov 13, 2017 at 21:39
  • I added to the original post the response I get after adding a -v... Nov 13, 2017 at 21:41
0

Try http://localhost:8545 instead of my-geth-remote-server. This is assuming you haven't edited your ~/.bash_profile. Hope this helps!

UPDATE: Here's a screenshot of me running the same command locally. Perhaps there's a problem with the remote instance. enter image description here Double check that the JSON you're sending is valid https://jsonlint.com/

2
  • Thanks, but I am trying to curl the remote geth server instead of geth on my localhost... Nov 13, 2017 at 21:34
  • ahh I see, I assumed it was a local development environment.
    – Malone
    Nov 13, 2017 at 21:36
0

For my issue using curl on Windows 10 with the environment variable already setup,

curl -X POST -H "Content-Type:application/json" --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\":[],\"id\":83}" https://some-node-url.com

I needed to replace all single quotes ' with double quotes "

even though the example I was using had a single quote.

And also add \ in front of all the double quotes inside the param brackets {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.