Hyperledger Composer 调用外部 REST API

Hyperledger composer calling external REST API

我是 hyperledger composer 的开发人员。我尝试将 Calling an HTTP or REST API from Transaction Processor Functions 与方法 POST 和请求正文一起使用,但我有错误状态代码 500。我想将方法​​ POST 与请求正文一起使用到我的服务器。

我的代码:

async function testStocks(transaction) {

    const participant = getCurrentParticipant();
    const json = '{"name:tester"}';//my request body

    await request.post({ uri: 'http://www...', json });

    // Update the current participant in the participant registry.
    const participantRegistry = await getParticipantRegistry('org.example.Trader');
    await participantRegistry.update(participant);

}

我的错误:

{
  "error": {
    "statusCode": 500,
    "name": "Error",
    "message": "Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined",
    "stack": "Error: Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: StatusCodeError: 400 - undefined\n    at _initializeChannel.then.then.then.then.catch (/home/pc/.nvm/versions/node/v8.10.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:965:34)\n    at <anonymous>"
  }
}

participant 变量在 await participantRegistry.update(participant); 中未定义。

您缺少示例中的代码@https://hyperledger.github.io/composer/latest/integrating/call-out

// Get the current participant, and update their stock and balance.
const participant = getCurrentParticipant();
// update participant here...  <<--------------------

// Update the current participant in the participant registry.
const participantRegistry = await getParticipantRegistry('org.example.Trader');
await participantRegistry.update(participant);