本文整理汇总了C++中HttpResponse类的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse类的具体用法?C++ HttpResponse怎么用?C++ HttpResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HttpResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: executeRequest
void Application::executeRequest(boost::function<void (HttpRequest*&, HttpResponse*&, void*)> convertData, void* data, boost::function<void (HttpRequest*, HttpResponse*)> requestFinish) {
//Create request
HttpRequest* request = NULL;
HttpResponse* response = NULL;
HttpSession* session = NULL;
convertData(request, response, data);
if(request==NULL||response==NULL) {
requestFinish(request, response);
return;
}
setContextToRequest(request);
if(mSessionManager) {
session = mSessionManager->startSession(*request, *response);
if(session) {
setSession(request, session);
}
}
IUrlHandler* urlHandler = getBeanFactory()->getBean<IUrlHandler>("urlHandler");
if(!urlHandler) {
if(mSessionManager && session) {
mSessionManager->endSession(session, *request, *response);
}
std::cout << "No URL Handler found set error page: 500" << std::endl;
requestFinish(request, response);
return;
}
if(!urlHandler->dispatchUrl(*request, *response)) {
if(mSessionManager && session) {
mSessionManager->endSession(session, *request, *response);
}
std::cout << "URL handle error set error page: 500" << std::endl;
requestFinish(request, response);
return;
}
if(mSessionManager && session) {
mSessionManager->endSession(session, *request, *response);
}
response->flush();
requestFinish(request, response);
}
示例2: TEST_F
TEST_F(HttpClientTest, Post)
{
HttpClient client;
HttpResponse response;
HttpClient::Options options;
HttpClient::ErrorCode error;
std::string data = "Post Content";
EXPECT_FALSE(client.Post(m_server_address + "/aaa/bbb",
data,
options,
&response,
&error));
EXPECT_NE(error, HttpClient::SUCCESS);
EXPECT_EQ(HttpResponse::Status_NotFound, response.Status());
}
示例3: onLcd
void onLcd(HttpRequest &request, HttpResponse &response)
{
int y = request.getQueryParameter("y").toInt();
String text = request.getQueryParameter("text");
setLcd(y, text);
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& json = stream->getRoot();
json["status"] = (bool)true;
response.setAllowCrossDomainOrigin("*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Request, X-Request, X-Requested-With");
response.sendJsonObject(stream);
}
示例4: onTune
void onTune(HttpRequest &request, HttpResponse &response)
{
setFrequency(request.getQueryParameter("freq").toFloat());
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& json = stream->getRoot();
json["status"] = (bool)true;
response.setAllowCrossDomainOrigin("*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Request, X-Request, X-Requested-With");
response.sendJsonObject(stream);
}
示例5: web_cb_scan_status
void web_cb_scan_status(HttpRequest &request, HttpResponse &response) {
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& json = stream->getRoot();
JsonArray& netlist = json.createNestedArray("available");
for (int i = 0; i < networks.count(); i++) {
JsonObject &item = netlist.createNestedObject();
item.add("id", (int)networks[i].getHashId());
item.add("title", networks[i].ssid.c_str());
item.add("signal", networks[i].rssi);
item.add("encryption", networks[i].getAuthorizationMethodName());
}
response.setAllowCrossDomainOrigin("*");
response.sendJsonObject(stream);
}
示例6: runHttpClientGetTest
static void runHttpClientGetTest(TestRunner& tr)
{
tr.test("Http Client GET");
// create client
HttpClient client;
// connect
Url url("http://www.bitmunk.com");
if(client.connect(&url))
{
printf("Connected to: %s\n", url.toString().c_str());
InternetAddress address(url.getHost().c_str(), url.getPort());
printf("%s\n", address.toString().c_str());
// do get
DynamicObject headers;
headers["Test-Header"] = "bacon";
HttpResponse* response = client.get(&url, &headers);
if(response != NULL)
{
printf("Response=\n%s\n", response->getHeader()->toString().c_str());
if(response->getHeader()->getStatusCode() == 200)
{
// receive content
HttpTrailer trailer;
File file("/tmp/index.html");
FileOutputStream fos(file);
if(client.receiveContent(&fos, &trailer))
{
printf("Content downloaded to '%s'\n",
file->getAbsolutePath());
printf("HTTP trailers=\n%s\n", trailer.toString().c_str());
}
assertNoExceptionSet();
}
}
else
{
printf("There was no response!\n");
}
client.disconnect();
}
tr.passIfNoException();
}
示例7: mqttOnHttpConfig
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
void mqttOnHttpConfig(HttpRequest &request, HttpResponse &response)
{
AppSettings.load();
if (!g_http.isHttpClientAllowed(request, response))
return;
if (request.getRequestMethod() == RequestMethod::POST) {
AppSettings.mqttUser = request.getPostParameter("user");
AppSettings.mqttPass = request.getPostParameter("password");
AppSettings.mqttServer = request.getPostParameter("server");
AppSettings.mqttPort = atoi(request.getPostParameter("port").c_str());
AppSettings.mqttClientId = request.getPostParameter("clientId");
AppSettings.save();
if (WifiStation.isConnected())
mqttStartClient();
} // if
TemplateFileStream *tmpl = new TemplateFileStream("mqtt.html");
auto &vars = tmpl->variables();
vars["appAlias"] = szAPP_ALIAS;
vars["user"] = AppSettings.mqttUser;
vars["password"] = AppSettings.mqttPass;
vars["server"] = AppSettings.mqttServer;
vars["port"] = AppSettings.mqttPort;
vars["clientId"] = AppSettings.mqttClientId;
response.sendTemplate(tmpl); // will be automatically deleted
} // mqttOnHttpConfig
示例8: initWebSocket
bool HttpServer::initWebSocket(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response)
{
if (!wsEnabled)
return false;
WebSocket *sock = new WebSocket(&connection);
if (!sock->initialize(request, response))
return false;
connection.setTimeOut(USHRT_MAX); //Disable disconnection on connection idle (no rx/tx)
connection.setDisconnectionHandler(HttpServerConnectionDelegate(&HttpServer::onCloseWebSocket, this)); // auto remove on close
response.sendHeader(connection); // Will push header before user data
wsocks.addElement(sock);
if (wsConnect) wsConnect(*sock);
if (wsCommandEnabled && (request.getQueryParameter(wsCommandRequestParam) == "true"))
{
#if ENABLE_CMD_EXECUTOR
debugf("WebSocket Commandprocessor started");
#else
debugf("WebSocket Commandprocessor support DISABLED via ENABLE_CMD_EXECUTOR");
#endif
sock->enableCommand();
}
}
示例9: onTest
/**
* just for testing
*/
void ICACHE_FLASH_ATTR onTest(HttpRequest &request, HttpResponse &response)
{
response.sendString("Hello, World!<br/>");
response.sendString("files:");
Vector<String> files=fileList();
for(int i=0;i<files.size();i++){
response.sendString(files[i]);
response.sendString("\r\n");
//ebugf("file %d=%s",i,files[i]);
}
}
示例10: OnTransactionCompleted
void HttpThread::OnTransactionCompleted(HttpSession & /*httpSession*/,
HttpTransaction & httpTransaction)
{
HttpResponse * pResponse = httpTransaction.GetResponse();
if (pResponse->GetHttpStatusCode() == HTTP_STATUS_OK
|| pResponse->GetHttpStatusCode() == HTTP_STATUS_PARTIAL_CONTENT)
{
m_callback.OnFinish(200, m_begRange, m_endRange);
}
else
{
LOG(LWARNING, ("Download has finished with status code:", pResponse->GetHttpStatusCode(),
" and text:", FromTizenString(pResponse->GetStatusText() )));
m_callback.OnFinish(-100, m_begRange, m_endRange);
}
}
示例11: AutocompleteScriptHelper
bool ConsoleHandler::AutocompleteScriptHelper(HttpRequest& request, HttpResponse& response,
const String& command, const String& session, bool sandboxed)
{
Log(LogInformation, "Console")
<< "Auto-completing expression: " << command;
ApiScriptFrame& lsf = l_ApiScriptFrames[session];
lsf.Seen = Utility::GetTime();
if (!lsf.Locals)
lsf.Locals = new Dictionary();
Array::Ptr results = new Array();
Dictionary::Ptr resultInfo = new Dictionary();
ScriptFrame frame;
frame.Locals = lsf.Locals;
frame.Self = lsf.Locals;
frame.Sandboxed = sandboxed;
resultInfo->Set("code", 200);
resultInfo->Set("status", "Auto-completed successfully.");
resultInfo->Set("suggestions", Array::FromVector(GetAutocompletionSuggestions(command, frame)));
results->Add(resultInfo);
Dictionary::Ptr result = new Dictionary();
result->Set("results", results);
response.SetStatus(200, "OK");
HttpUtility::SendJsonBody(response, result);
return true;
}
示例12: onIndex
void onIndex(HttpRequest &request, HttpResponse &response)
{
TemplateFileStream *tmpl = new TemplateFileStream("index.html");
auto &vars = tmpl->variables();
//vars["counter"] = String(counter);
response.sendTemplate(tmpl); // this template object will be deleted automatically
}
示例13: onAjaxInput
void onAjaxInput(HttpRequest &request, HttpResponse &response)
{
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& json = stream->getRoot();
json["status"] = (bool)true;
String stringKey = "StringKey";
String stringValue = "StringValue";
json[stringKey] = stringValue;
for( int i = 0; i < 11; i++)
{
char buff[3];
itoa(i, buff, 10);
String desiredString = "sensor_";
desiredString += buff;
json[desiredString] = desiredString;
}
JsonObject& gpio = json.createNestedObject("gpio");
for (int i = 0; i < countInputs; i++)
gpio[namesInput[i].c_str()] = digitalRead(inputs[i]);
response.sendJsonObject(stream);
}
示例14: getSession
HttpSession HttpSessionStore::getSession(HttpRequest& request, HttpResponse& response, bool allowCreate) {
QByteArray sessionId=getSessionId(request,response);
mutex.lock();
if (!sessionId.isEmpty()) {
HttpSession session=sessions.value(sessionId);
if (!session.isNull()) {
mutex.unlock();
session.setLastAccess();
return session;
}
}
// Need to create a new session
if (allowCreate) {
QByteArray cookieName=settings->value("cookieName","sessionid").toByteArray();
QByteArray cookiePath=settings->value("cookiePath","/").toByteArray();
QByteArray cookieComment=settings->value("cookieComment").toByteArray();
QByteArray cookieDomain=settings->value("cookieDomain").toByteArray();
HttpSession session(true);
qDebug("HttpSessionStore: create new session with ID %s",session.getId().data());
sessions.insert(session.getId(),session);
response.setCookie(HttpCookie(cookieName,session.getId(),expirationTime/1000,cookiePath,cookieComment,cookieDomain));
mutex.unlock();
return session;
}
// Return a null session
mutex.unlock();
return HttpSession();
}
示例15: onMute
void onMute(HttpRequest &request, HttpResponse &response)
{
setMmute(!mute);
JsonObjectStream* stream = new JsonObjectStream();
JsonObject& json = stream->getRoot();
json["status"] = (bool)true;
json["state"] = (bool)mute;
response.setAllowCrossDomainOrigin("*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Request, X-Request, X-Requested-With");
response.sendJsonObject(stream);
}