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


C++ HttpResponse类代码示例

本文整理汇总了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);
}
开发者ID:fkrauthan,项目名称:CppWebMVC,代码行数:49,代码来源:Application.cpp

示例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());
}
开发者ID:KangRoger,项目名称:toft,代码行数:15,代码来源:client_test.cpp

示例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);
}
开发者ID:avtehnik,项目名称:esp8266-music-box,代码行数:15,代码来源:application.cpp

示例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);
	
}
开发者ID:avtehnik,项目名称:esp8266-music-box,代码行数:15,代码来源:application.cpp

示例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);
}
开发者ID:Bravo13,项目名称:esp_hello_world,代码行数:15,代码来源:utils.cpp

示例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();
}
开发者ID:bsletten,项目名称:monarch,代码行数:48,代码来源:test-http.cpp

示例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
开发者ID:yunjova,项目名称:wiControl,代码行数:32,代码来源:mqtt.cpp

示例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();
    }
}
开发者ID:blinkingnoise,项目名称:Sming,代码行数:25,代码来源:HttpServer.cpp

示例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]);
	}

}
开发者ID:gernoteger,项目名称:DobbyESP,代码行数:19,代码来源:application.cpp

示例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);
  }
}
开发者ID:DINKIN,项目名称:omim,代码行数:16,代码来源:http_thread_tizen.cpp

示例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;
}
开发者ID:Thomas-Gelf,项目名称:icinga2,代码行数:34,代码来源:consolehandler.cpp

示例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
}
开发者ID:zhivko,项目名称:Sming,代码行数:7,代码来源:application.cpp

示例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);
}
开发者ID:BorntraegerMarc,项目名称:Sming,代码行数:27,代码来源:application.cpp

示例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();
}
开发者ID:Skelly1983,项目名称:yacreader,代码行数:28,代码来源:httpsessionstore.cpp

示例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);
}
开发者ID:avtehnik,项目名称:esp8266-music-box,代码行数:16,代码来源:application.cpp


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