2016-06-10 55 views
2

我正在尝试将请求从google api脚本发送到IBM Blockchain SaaS项目Bluemix。 的代码是:Google API向IBM区块链错误发布请求

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海报请求被正确地回答。

+0

无法看到任何代码,将身体放入帖子中寻求。或者我错过了什么? – barny

回答

1

您指定查询作为参数传递给方法功能,但如果你想使用自定义功能进行查询(然后指定方法查询功能自定义函数名你已经在chaincode中创建)如下:

{"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" 
    },