【问题标题】:Hyperledger composer calling external REST API调用外部 REST API 的超级账本作曲家
【发布时间】:2018-03-30 19:14:31
【问题描述】:

我是一名超级账本作曲家的开发者。我尝试将 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>"
  }
}

【问题讨论】:

    标签: hyperledger hyperledger-composer


    【解决方案1】:

    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);
    

    【讨论】:

    • 哦,我看到你实际上已经在上面定义了。我的错。
    • 现在,它工作正常,但我的 CORS 有错误。兄弟能帮帮我吗。。我用过 cors-anywhere.herokuapp.com 但它只适用于浏览器。我的错误:The response had HTTP status code 405. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    • 为了解决CORS,我实际上是更改了源代码并添加了CORS头。
    猜你喜欢
    • 2022-11-10
    • 1970-01-01
    • 2018-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多