How to use jsonrpc via curl?

Hello, how can I make jsonrpc calls via CURL? I’ve tried

curl --location --request POST  localhost:7080  --header "Content-Type: application/json" --data-raw '{"jsonrpc":"2.0","method":"core.show.version","params":[],"id":1}'         

but it says curl: (52) Empty reply from server

thanks a lot

jsonrpc is not using HTTP as transport, so curl is useless there. read JSON-RPC 2.0 Specification

thank you for your reply, I never used jsonrpc before, I would like to contact jsonrpc through PHP, so I guess I would need some library. Thanks!

If it’s possible, can you give me an example on how can I make a request to jsonrpc remotely via command line?
Thanks

use yeti-cli Yeti CLI utility — Yeti documentation

is there a way to send a single command and receive a response? for example yeti-cli 127.0.0.1:7080 core.show.version .
I’d need something like that.
Thanks!

currently there is only interactive mode, but you could create feature request there GitHub - yeti-switch/yeti-cli: Command-Line interface for YETI system or even propose patch(if you know python)

ok, I will try to add this feature using python
Thanks a lot

I’m not an expert of python but here there is a class adapted for the single call request type:

class CommandLineCall:
    def rpc_do_dotted(self,addr, method, args, verbose = False):
        method = method.rstrip('.')
        for i,a in enumerate(args):
            if a=='empty':
                args[i] = ''
        j = JsonRpcProxy(addr,5)
        return j.call_remote(method,args,verbose)

   

if __name__ == '__main__':
    try:
        addr = sys.argv[1] 
    except:
         addr = False
    try:
        command = sys.argv[2]
    except:
         command = False
    try:
        parameters = sys.argv[3]
    except:
        parameters = []
    try:
        if (addr and command):
            data =  CommandLineCall().rpc_do_dotted(addr,command,parameters)
            print(data)
        else:
            print('interactive mode')
            syslog.syslog("Session started")
            print('yeti-cli version {}'.format(__version__))
            Shell().cmdloop()
    except IOError as e:
        print(e)
    except KeyboardInterrupt as e:
        print('')

it’s a first simple prototype, I can only get informations from remote nodes but I’m not able to pass parameters right now.
Command line example:

# yeti-cli 127.0.0.1 yeti.show.calls.count
190

I made the class in a way it can be merged on the current project if you need, but it needs to be revised and fixed for errors handling I guess.
Hope you’ll appreciate

could you create pull request on github?

ok, done, I made a new file yeti-cmd just for this kind of use, in this way you can move just this file in every server you want without dependencies problem