2
curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: XXXXXXX" -H "Origin: https://XXXXXXX/" -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://XXXXXXX/
HTTP/2 405 
server: nginx/1.18.0
date: Fri, 26 Feb 2021 13:56:20 GMT
content-type: text/plain; charset=utf-8
content-length: 19
sec-websocket-version: 13
x-content-type-options: nosniff

Method Not Allowed

geth is running with websockets enabled with the following settings: --ws --ws.port 8546 --ws.api eth,net,web3 --ws.origins '*' --ws.addr 0.0.0.0 and is behind an nginx reverse proxy:

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade "websocket"; # $http_upgrade;
        proxy_set_header Connection "upgrade"; # $connection_upgrade;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://XXXXXX;
    }

I have also tried eth version command, same result. Same error when I connect to the websocket directly, not through nginx.

1 Answer 1

2

OK, the issue is that several guides on how to connect to websockets using Curl don't work on geth's websocket for whatever reason. Using a tool specifically for websockets allowed the requests to go through just fine.

$ wscat -c wss://XXXXXXXXXX/
connected (press CTRL+C to quit)
> {"jsonrpc":"2.0","method":"web3_sha3","params":["0x68656c6c6f20776f726c64"],"id":64}
< {"jsonrpc":"2.0","id":64,"result":"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"}

Your Answer

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

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