调用 REST 请求并处理 REST 响应
Calling REST request and handling REST response
休息请求
POST host:port/chaincode
{
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID":{
"path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"function":"init",
"args":["a", "1000", "b", "2000"]
}
},
"id": 1
}
休息反应
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "52b0d803fc395b5e34d8d4a7cd69fb6aa00099b8fabed83504ac1c5d61a425aca5b3ad3bf96643ea4fdaac132c417c37b00f88fa800de7ece387d008a76d3586"
},
"id": 1
}
我有这组request和response,他们说接口端口是5000,这个rest request和alert response结果怎么调用?我试过 jquery 但我做不到。他们一直提示我 window 错误。
这是我试过的
$.post('localhost:5000/chaincode', {
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"path": "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"function": "init",
"args": ["a", "1000", "b", "2000"]
}
},
"id": 1
}, function (serverResponse) {
alert(serverResponse);
//do what you want with server response
})
你的代码看起来不错。
我在发送请求时看到的唯一可能问题是该服务可能 运行 在您的本地主机上。
根据规范,结果是一个对象。由于 alert()
只会打印 [object]
,因此最好使用 console.log()
进行调试输出。
休息请求
POST host:port/chaincode
{
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID":{
"path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"function":"init",
"args":["a", "1000", "b", "2000"]
}
},
"id": 1
}
休息反应
{
"jsonrpc": "2.0",
"result": {
"status": "OK",
"message": "52b0d803fc395b5e34d8d4a7cd69fb6aa00099b8fabed83504ac1c5d61a425aca5b3ad3bf96643ea4fdaac132c417c37b00f88fa800de7ece387d008a76d3586"
},
"id": 1
}
我有这组request和response,他们说接口端口是5000,这个rest request和alert response结果怎么调用?我试过 jquery 但我做不到。他们一直提示我 window 错误。
这是我试过的
$.post('localhost:5000/chaincode', {
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"path": "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02"
},
"ctorMsg": {
"function": "init",
"args": ["a", "1000", "b", "2000"]
}
},
"id": 1
}, function (serverResponse) {
alert(serverResponse);
//do what you want with server response
})
你的代码看起来不错。
我在发送请求时看到的唯一可能问题是该服务可能 运行 在您的本地主机上。
根据规范,结果是一个对象。由于 alert()
只会打印 [object]
,因此最好使用 console.log()
进行调试输出。