zoukankan      html  css  js  c++  java
  • c++ 开发http服务,解析http消息

    #include <QCoreApplication>
    #include "serverhttp.h"
    #include "msghttp.h"
    #include <QDebug>
    #include <QDateTime>
    
    class HttpHandle : public LarkinHttp::MsgHandle
    {
    public:
        void doFunction(LarkinHttp::MsgRequest* req, LarkinHttp::MsgResponse* res) override;
    };
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        LarkinHttp::ServerHttp server;
        if(!server.init(8888)){
            return 0;
        }
        server.setHandleNumber(2);
        HttpHandle handle;
        server.applyHandle(&handle);
        server.workEnable(true);
    
        return a.exec();
    }
    
    void HttpHandle::doFunction(LarkinHttp::MsgRequest *req, LarkinHttp::MsgResponse *res)
    {
        qDebug() << "method:" << req->strMethod
                 << " url:" << req->strUrl;
        res->strCode = "200";
        res->strDesc = "OK";
        res->strContentType = "text/plain";
        res->strBody = QString("[%1] hello").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz"));
    }

    说明:

    #include "serverhttp.h"
    #include "msghttp.h"

    自己封装的库,里面自动多线程解析消息。
  • 相关阅读:
    函数模板——隐式实例化、显式实例化、显式具体化
    SQLAlchemy
    pymysql的使用
    mysql 安装
    Django---Cerley使用
    支付宝支付功能
    Django--log配置
    Vue--基础
    Python学习手册
    针对特定网站scrapy爬虫的性能优化
  • 原文地址:https://www.cnblogs.com/larkin-cn/p/14817666.html
Copyright © 2011-2022 走看看