SHARE
TWEET

Untitled

a guest Jun 23rd, 2011 1,517 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <QCoreApplication>
  2. #include <QRegExp>
  3. #include <QStringList>
  4.  
  5. #include <qhttpserver.h>
  6. #include <qhttprequest.h>
  7. #include <qhttpresponse.h>
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.     QCoreApplication app{argc, argv};
  12.  
  13.     QHttpServer *server = new QHttpServer;
  14.     server->listen(QHostAddress::Any, 5000);
  15.     QObject::connect(server, &QHttpServer::newRequest, [](QHttpRequest *req, QHttpResponse *resp) {
  16.         QRegExp exp{"^/user/([a-z]+)$"};
  17.         if(exp.indexIn(req->path()) != -1 ) {
  18.             resp->setHeader("Content-Type", "text/html");
  19.             resp->writeHead(200);
  20.             QString name = exp.capturedTexts()[1];
  21.  
  22.             auto reply = "<html><head><title>Greeting App</title></head><body><h1>Hello "
  23.                 + name
  24.                 + "</h1></body></html>";
  25.             resp->end(reply);
  26.         } else {
  27.             resp->writeHead(403);
  28.             resp->end("You aren't allowed here!");
  29.         }
  30.     });
  31.  
  32.     return app.exec();
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top