当前位置: 首页>>代码示例>>C++>>正文


C++ HttpParser::receiveResponse方法代码示例

本文整理汇总了C++中HttpParser::receiveResponse方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpParser::receiveResponse方法的具体用法?C++ HttpParser::receiveResponse怎么用?C++ HttpParser::receiveResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpParser的用法示例。


在下文中一共展示了HttpParser::receiveResponse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sendRequest

void RPCTestNode::sendRequest(const HttpRequest& httpReq, HttpResponse& httpResp) {
  TcpConnector connector(m_dispatcher, "127.0.0.1", m_rpcPort);
  TcpConnection connection = connector.connect();
  TcpStreambuf streambuf(connection);
  std::iostream connectionStream(&streambuf);
  LOG_DEBUG("invoke rpc:" + httpReq.getMethod() + " " + httpReq.getBody());
  connectionStream << httpReq;
  connectionStream.flush();
  HttpParser parser;
  parser.receiveResponse(connectionStream, httpResp);  
}
开发者ID:AlbertWerner,项目名称:cryptonotecoin,代码行数:11,代码来源:RPCTestNode.cpp

示例2: submitBlock

bool RPCTestNode::submitBlock(const std::string& block) {
  HttpRequest httpReq;
  httpReq.setUrl("/json_rpc");
  httpReq.addHeader("Host", "127.0.0.1:" + boost::lexical_cast<std::string>(m_rpcPort));
  httpReq.addHeader("Content-Type", "application/json-rpc");
  JsonValue request(cryptonote::JsonValue::OBJECT);
  JsonValue jsonRpc;
  jsonRpc = "2.0";
  request.insert("jsonrpc", jsonRpc);
  JsonValue methodString;
  methodString = "submitblock";
  request.insert("method", methodString);
  JsonValue id;
  id = "sync";
  request.insert("id", id);
  JsonValue params(JsonValue::ARRAY);
  JsonValue blockstr;
  blockstr = block.c_str();
  params.pushBack(blockstr);
  request.insert("params", params);
  std::stringstream jsonOutputStream;
  jsonOutputStream << request;
  httpReq.setBody(jsonOutputStream.str());
  TcpConnector connector(m_dispatcher, "127.0.0.1", m_rpcPort);
  TcpConnection connection = connector.connect();
  TcpStreambuf streambuf(connection);
  std::iostream connectionStream(&streambuf);
  LOG_DEBUG("invoke json-rpc: " + httpReq.getBody());
  connectionStream << httpReq;
  connectionStream.flush();
  HttpResponse httpResp;
  HttpParser parser;
  parser.receiveResponse(connectionStream, httpResp);
  connectionStream.flush();
  if (httpResp.getStatus() != HttpResponse::STATUS_200) return false;

  epee::serialization::portable_storage ps;
  if (!ps.load_from_json(httpResp.getBody())) {
    LOG_ERROR("cannot parse response from daemon: " + httpResp.getBody());
    return false;
  }

  epee::json_rpc::response<COMMAND_RPC_SUBMITBLOCK::response, epee::json_rpc::error> jsonRpcResponse;
  jsonRpcResponse.load(ps);

  if (jsonRpcResponse.error.code || jsonRpcResponse.error.message.size()) {
    LOG_ERROR("RPC call of submit_block returned error: " + TO_STRING(jsonRpcResponse.error.code) + ", message: " + jsonRpcResponse.error.message);
    return false;
  }
   
  if (jsonRpcResponse.result.status != CORE_RPC_STATUS_OK)  return false;
  return true;
}
开发者ID:AlbertWerner,项目名称:cryptonotecoin,代码行数:53,代码来源:RPCTestNode.cpp

示例3: request

void HttpClient::request(const HttpRequest &req, HttpResponse &res) {
  if (!m_connected) {
    connect();
  }

  try {
    std::iostream stream(m_streamBuf.get());
    HttpParser parser;
    stream << req;
    stream.flush();
    parser.receiveResponse(stream, res);
  } catch (const std::exception &) {
    disconnect();
    throw;
  }
}
开发者ID:3695StephenJohnson,项目名称:cryptonote,代码行数:16,代码来源:HttpClient.cpp


注:本文中的HttpParser::receiveResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。