[Ethereum] Geth response: invalid content type, only application/json is supported


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

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}' -v

* Rebuilt URL to:
* timeout on name lookup is not supported
*   Trying
* Connected to ( port 8545 (#0)
> POST / HTTP/1.1
> Host:
> 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 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.

Best Answer

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