【问题标题】:Google API post request to IBM blockchain error对 IBM 区块链错误的 Google API 发布请求
【发布时间】:2016-06-10 10:25:31
【问题描述】:

我正在尝试将请求从 google api 脚本发送到 IBM Blockchain SaaS 项目 Bluemix。 代码是:

var url = "https://24f7d912-60f4-4eaf-89c6-b3e34b2247f9_vp1-api.blockchain.ibm.com:443/chaincode";
  var headers =
  {"jsonrpc": "2.0",
   "method": "query",
   "params": {
       "type": 1,
       "chaincodeID": {
           "name": "c86de893fe7203e09add8c47237ffa377814311d9c3cb21ca4d3d5c4eeca65294d801a1f2e5a2d6b22b91096d9c8e42910046d2ab02d295ad0a0fb0b716e9a69"
       },
       "ctorMsg": {
           "function": "query",
           "args": ["b"]
        },
        "secureContext": "dashboarduser_type0_953add49d4"
    },
    "id": 1
  };
  var options =
     {
      "method" : "post",
      "headers" : headers,
       "MuteHttpExceptions":false
     };
  var response = UrlFetchApp.fetch(url,options);
  var responseString=response.getContentText();  
}

错误信息是:

{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request","data":"Client must supply a payload for chaincode requests."},"id":null}

Firefix Poster 的请求得到了正确答复。

【问题讨论】:

  • 看不到任何将正文放入发布请求的代码。还是我错过了什么?

标签: api post ibm-cloud blockchain


【解决方案1】:

您已将 query 指定为 methodfunction 的参数,但如果您尝试使用自定义函数进行查询(然后指定 方法 作为 queryfunction 作为 custom function 您在链代码中创建的名称)作为:

{"jsonrpc": "2.0",
"method": "query",
   "params": {
       "type": 1,
       "chaincodeID": {
           "name": "chainId"
       },
       "ctorMsg": {
           "function": "customfunctionName",
           "args": ["b"] //Argument to that custom function
        },
        "secureContext": "dashboarduser_type0_953add49d4"
    },

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-13
    • 2021-05-12
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多