本文整理汇总了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);
}
示例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;
}
示例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;
}
}