本文整理汇总了C++中HttpResponse::getStatus方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::getStatus方法的具体用法?C++ HttpResponse::getStatus怎么用?C++ HttpResponse::getStatus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::getStatus方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strlen
void
dynamic_1B(TestArg *arg)
{
char *uri;
HttpEngine engine;
HttpRequest *request;
HttpResponse *response;
arg->returnVal = 0;
uri = (char *)malloc(sizeof(TEST_QUERY) + strlen(arg->uri) + 2);
sprintf(uri, "%s?%s", arg->uri, TEST_QUERY);
request = new HttpRequest(arg->server, uri, arg->proto);
request->setExpectDynamicBody();
response = engine.makeRequest(*request);
if (response->getStatus() != 200) {
Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus());
arg->returnVal = -1;
}
char *query = response->getDynamicResponse().lookupValue("BASIC", "queryString");
if (!query || strcmp(query, TEST_QUERY)) {
Logger::logError(LOGERROR, "query string mismatch! (\"%s\")", query);
arg->returnVal = -1;
}
free(uri);
delete request;
delete response;
}
示例2: request
void
dynamic_1D(TestArg *arg)
{
HttpEngine engine;
HttpRequest request(arg->server, arg->uri, arg->proto);
HttpResponse *response;
char header[1024], value[1024];
arg->returnVal = 0;
memset(header, 'X', 1024);
header[1024-1] = '\0';
memset(value, 'Y', 1024);
value[1024-1] = '\0';
request.addHeader(header,value);
request.setExpectDynamicBody();
response = engine.makeRequest(request);
if (response->getStatus() != 200) {
Logger::logError(LOGERROR, "server responded with status code %d", response->getStatus());
arg->returnVal = -1;
}
char *rvheader = response->getDynamicResponse().lookupValue("REQUEST HEADERS", header);
if (!rvheader || strcmp(rvheader, value)) {
fprintf(stdout, "strlen(rvheader) is %d\n", strlen(rvheader));
fprintf(stdout, "strlen(header) is %d\n", strlen(header));
Logger::logError(LOGERROR, "long header mismatch! (\"%s\")", rvheader);
arg->returnVal = -1;
}
delete response;
}
示例3: startMining
bool RPCTestNode::startMining(size_t threadsCount, const std::string& address) {
LOG_DEBUG("startMining()");
using namespace cryptonote;
COMMAND_RPC_START_MINING::request req;
COMMAND_RPC_START_MINING::response resp;
req.miner_address = address;
req.threads_count = threadsCount;
std::stringstream requestStream;
JsonOutputStreamSerializer enumerator;
enumerator(req, "");
requestStream << enumerator;
HttpRequest httpReq;
prepareRequest(httpReq, "/start_mining", requestStream.str());
HttpResponse httpResp;
sendRequest(httpReq, httpResp);
if (httpResp.getStatus() != HttpResponse::STATUS_200) return false;
std::stringstream responseStream(httpResp.getBody());
JsonInputStreamSerializer en(responseStream);
en(resp, "");
if (resp.status != CORE_RPC_STATUS_OK) {
std::cout << "startMining() RPC call fail: " << resp.status;
return false;
}
return true;
}
示例4: service
/**
* @brief PathDelegator::service -- Delegate the request to the service designed to handle that request
* @param request
* @param response
*/
void PathDelegator::service(HttpRequest &request, HttpResponse &response) {
QByteArray path = removeExtension(request.getPath());
if (paths.contains(path)) {
paths[path]->service(request, response);
}
else {
response.setStatus(HttpHeaders::STATUS_NOT_FOUND, QByteArray("Cannot find ") + path);
}
WebLogger::log(QtWarningMsg, QByteArray::number(response.getStatus()) + ": " + response.getStatusText(), "pathdelegator", "service");
}
示例5: invokeJsonRpcCommand
void invokeJsonRpcCommand(HttpClient& httpClient, JsonRpcRequest& jsReq, JsonRpcResponse& jsRes) {
HttpRequest httpReq;
HttpResponse httpRes;
httpReq.setUrl("/json_rpc");
httpReq.setBody(jsReq.getBody());
httpClient.request(httpReq, httpRes);
if (httpRes.getStatus() != HttpResponse::STATUS_200) {
throw std::runtime_error("JSON-RPC call failed, HTTP status = " + std::to_string(httpRes.getStatus()));
}
jsRes.parse(httpRes.getBody());
JsonRpcError err;
if (jsRes.getError(err)) {
throw err;
}
}
示例6: 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;
}
示例7: stopDaemon
bool RPCTestNode::stopDaemon() {
LOG_DEBUG("stopDaemon()");
using namespace cryptonote;
COMMAND_RPC_STOP_DAEMON::request req;
COMMAND_RPC_STOP_DAEMON::response resp;
std::stringstream requestStream;
JsonOutputStreamSerializer enumerator;
enumerator(req, "");
requestStream << enumerator;
HttpRequest httpReq;
prepareRequest(httpReq, "/stop_daemon", requestStream.str());
HttpResponse httpResp;
sendRequest(httpReq, httpResp);
if (httpResp.getStatus() != HttpResponse::STATUS_200) return false;
std::stringstream responseStream(httpResp.getBody());
JsonInputStreamSerializer en(responseStream);
en(resp, "");
if (resp.status != CORE_RPC_STATUS_OK) {
std::cout << "stopDaemon() RPC call fail: " << resp.status;
return false;
}
return true;
}
示例8: processResponse
void processResponse(HttpResponse resp){
if(resp.getStatus() == HttpResponse::OK_200){
}
}
示例9: do_child
//.........这里部分代码省略.........
set_status = true;
}
}
else if(set_status == false)
{
std::ifstream file;
file.exceptions(
std::ifstream::badbit
| std::ifstream::eofbit);
file.open(filepath, std::ifstream::in | std::ifstream::binary | std::ifstream::out);
if (!file.is_open())
{
status.m_statuscode = "404";
response.setStatus(status);
response.setDescription ("Not Found");
response.setHeader("Content-Length", "0");
set_status = true;
}
else
{
status.m_statuscode = "200";
response.setStatus(status);
response.setDescription ("OK");
set_status = true;
file.seekg(0, std::ios::end);
std::streampos length(file.tellg());
if (length) {
file.seekg(0, std::ios::beg);
pload.resize(static_cast<std::size_t>(length));
file.read(&pload.front(), static_cast<std::size_t>(length));
}
file.close();
response.setPayLoad(pload);
std::stringstream out;
p_size = pload.size();
out << p_size;
response.setHeader("Content-Length", out.str());
}
memset(filepath, '\0', 100);
}
res_wire = response.encode();
int wsize = res_wire.size();
memset(buf, '\0', sizeof(buf));
for (int k1 = 0; k1 < wsize; k1++) {
buf[k1] = res_wire[k1];
}
res_wire.clear();
if (send(fd, buf, wsize, 0) == -1) {
perror("send");
exit(1);
}
if(response.getStatus().m_statuscode == "200")
{
int divide = p_size/500;
int remainder = p_size % 500;
int count = 0;
for (int k = 0; k < divide; k++) {
memset(buf, '\0', sizeof(buf));
for (int k1 = 0; k1 < 500; k1++) {
buf[k1] = pload[count];
count ++;
}
if (send(fd, buf, 500, 0) == -1) {
perror("send");
exit(1);
}
}
if(remainder!=0)
{
memset(buf, '\0', sizeof(buf));
for(int q = 0; q < remainder; q++)
{
buf[q] = pload[count];
count++;
}
if (send(fd, buf, remainder, 0) == -1) {
perror("send");
exit(1);
}
}
}
pload.clear();
if(response.getMap("Connection") == "close")
{
std::cout << "successfully close the connection" <<std::endl;
close(fd);
break;
}
}
}