【问题标题】:JSONRPC request with curl带有 curl 的 JSONRPC 请求
【发布时间】:2014-06-23 14:40:07
【问题描述】:

对于使用字典作为参数的所有请求,我都有一个 32602 错误,而这些使用简单的参数。

例如:

curl -d '{"id":"json","method":"add","params":[1,2] }' -o – ‘http address for json rpc’

有效,但是:

curl -d '{"id":"json","method":"add","params":[{"a":2,"b":3}] }' -o – ‘http address for json rpc’’

返回 32602 错误(无效参数!!!)

我需要在 params 中输入名称和类型,并且为此需要一个字典,但我收到 32602 错误。怎么了?

【问题讨论】:

    标签: json curl json-rpc


    【解决方案1】:

    您收到的特定错误(“无效参数”)确实表明您的参数类型对于您正在调用的特定方法可能是错误的,但对于寻求使用 curl 进行 JSON-RPC 调用的一般指导的任何人,可能不是问题。

    对于 JSON-RPC 2.0,规范要求传递指定协议版本的字符串 "jsonrpc": "2.0",该问题的示例中缺少该字符串。

    这是一个合规的工作调用示例(使用jayson 服务器测试):

    curl -X POST \
         -H 'Content-Type: application/json' \
         -d '{"jsonrpc":"2.0","id":"id","method":"add","params":[1, 2]}' \
         http://localhost:3000
    

    【讨论】:

      【解决方案2】:

      在您的第二次尝试中,尝试从对象括号周围删除数组括号 []。

      喜欢:

      curl -d '{"id":"json","method":"add","params":{"a":2,"b":3} }' -o – [http address for json rpc]
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-08
      • 2016-06-14
      • 2021-04-15
      • 2011-10-30
      • 2018-03-13
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多