本文整理汇总了C++中HTTPRequest::post方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPRequest::post方法的具体用法?C++ HTTPRequest::post怎么用?C++ HTTPRequest::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPRequest
的用法示例。
在下文中一共展示了HTTPRequest::post方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogInfo
Node *Parser::parse(uHTTP::URL *url) {
LogInfo("parse,TID(0x%04x): %s\n", GetCurrentThreadId(), url->getSting());
HTTPRequest httpReq;
HTTPResponse *httpRes = NULL;
{
FUNCTION_BLOCK_NAME_TRACE("post", 100);
const char *host = url->getHost();
int port = url->getPort();
std::string target = url->getTarget();
httpReq.setMethod(HTTP::GET);
httpReq.setURI(target);
httpRes = httpReq.post(host, port);
if (httpRes->isSuccessful() == false){
return NULL;
}
}
Node* pNode = NULL;
{
FUNCTION_BLOCK_NAME_TRACE("ParseContent", 100);
const char *contents = httpRes->getContent();
pNode = parse(contents);
}
return pNode;
}
示例2: writeToDataBase
/**
* DBInterface::writeToDataBase
* @brief writeToDataBase writes content of dataBuffer_ to database
* @param dataBuffer_ data which is written to database
*/
void DBInterface::writeToDataBase(DataBuffer& dataBuffer_) {
if (readStatusOK()) {
stringstream httpRequestUrl;
httpRequestUrl << URL_OF_DATABASE << "/write?db=" << NAME_OF_DATBASE << "&precision=s";
stringstream httpRequestPostFields;
if (!dataBuffer_.useDataSource) {
log << SLevel(ERROR) << "Aborted writing to database because there was either no DataSource specified" <<
" or the useDataSource-flag was not set to true." << endl;
} else {
string dataSource = cleanString(dataBuffer_.dataSource);
httpRequestPostFields << "point,DataSource=" << dataSource << " ";
bool printComma = false;
typedef std::map<string, double>::iterator it_type;
for(it_type iterator = dataBuffer_.data.begin(); iterator != dataBuffer_.data.end(); iterator++) {
if (printComma) {
httpRequestPostFields << ",";
} else {
printComma = true;
}
string name = cleanString(iterator->first);
double value = cutValueToInfluxDBRange(iterator->second);
httpRequestPostFields << name << "=" << value;
}
// create datetime-string
if (dataBuffer_.useDateTimes) {
if (dataBuffer_.startDateTime.tm_year <= 1971) {
log << SLevel(ERROR) << "Aborted writing to database because of invalid datetime. " <<
"Please use only years bigger than 1971." << endl;
setDBFailure(true);
return;
} else {
string startDateTime = cTimeToString(dataBuffer_.startDateTime,true);
httpRequestPostFields << " " << startDateTime;
}
} else {
// if no date-time is specified use local time (cut down to current hour)
int currentLocalDateTime = getCurrentDateTimeAsUnixTime();
string startDateTime = to_string(currentLocalDateTime);
httpRequestPostFields << " " << startDateTime;
}
HTTPRequest req;
bool noFailure = req.post(httpRequestUrl.str(),httpRequestPostFields.str());
setDBFailure(!noFailure);
}
} else {
log << SLevel(ERROR) << "Aborted writing to database because of status not OK" << endl;
}
}
示例3: parse
Node *Parser::parse(uHTTP::URL *url)
{
const char *host = url->getHost();
int port = url->getPort();
const char *uri = url->getPath();
HTTPRequest httpReq;
httpReq.setMethod(HTTP::GET);
httpReq.setURI(uri);
HTTPResponse *httpRes = httpReq.post(host, port);
if (httpRes->isSuccessful() == false)
return NULL;
const char *contents = httpRes->getContent();
return parse(contents);
}
示例4: writeStatusOK
/**
* DBInterface::writeStatusOK
* @brief writes the boolean value statusOK_ to database
* @param statusOK_ boolean value which is wirtten to the database
*/
void DBInterface::writeStatusOK(bool statusOK_) {
stringstream httpRequestUrl;
stringstream httpRequestPostFields;
HTTPRequest req;
// try to delete old value from influxDB
// (post writes an error to log, if there is nothing to delete)
httpRequestUrl << URL_OF_DATABASE << "/query?db=" << NAME_OF_DATBASE;
httpRequestPostFields << "q=drop measurement statusOK";
req.post(httpRequestUrl.str(),httpRequestPostFields.str());
// write new value to influxDB
stringstream httpRequestUrl2;
stringstream httpRequestPostFields2;
httpRequestUrl2 << URL_OF_DATABASE << "/write?db=" << NAME_OF_DATBASE << "&precision=s";
httpRequestPostFields2 << "statusOK value=" << statusOK_;
bool noFailure = req.post(httpRequestUrl2.str(),httpRequestPostFields2.str());
setDBFailure(!noFailure);
if (!noFailure) {
log << SLevel(ERROR) << "Aborted writing statusOK to database because http-post was not possible." << endl;
}
}
示例5: performQueryListener
bool StateVariable::performQueryListener(QueryRequest *queryReq)
{
QueryListener *listener = getQueryListener();
if (listener == NULL)
return false;
QueryResponse queryRes;
StateVariable retVar;
retVar.set(this);
retVar.setValue("");
retVar.setStatus(UPnP::INVALID_VAR);
if (listener->queryControlReceived(&retVar) == true) {
queryRes.setResponse(&retVar);
}
else {
UPnPStatus *upnpStatus = retVar.getStatus();
queryRes.setFaultResponse(upnpStatus->getCode(), upnpStatus->getDescription());
}
HTTPRequest *httpReq = queryReq;
httpReq->post(&queryRes);
return true;
}
示例6: createIfNotCreatedDataBase
/**
* DBInterface::createIfNotCreatedDataBase
* @brief creates database defined by NAME_OF_DATBASE in config.h if not already created
*/
void DBInterface::createIfNotCreatedDataBase() {
HTTPRequest request;
request.post(URL_OF_DATABASE + "/query?q=create+database+"+NAME_OF_DATBASE+"&db=_internal","");
}