在服务器上获取发布请求并将其转换为json

时间:2019-01-28 15:59:43

标签: c++ json qt qtcpsocket qtcpserver

这是一个简单的Qt C ++ HTTP服务器。

当我尝试发送帖子请求时,我看到下一个输出

  

“ POST /?test = 23&someKey = 42 HTTP / 1.1”   

如何将其转换为json?

tcpServer = new QTcpServer();
if (!tcpServer->listen(QHostAddress::Any, 2323)) {
    qDebug() << "ERROR: " << tcpServer->errorString();
    return;
}
qDebug() << "Ip: " << tcpServer->serverAddress();
qDebug() << "Port: " << tcpServer->serverPort();

QObject::connect(tcpServer, &QTcpServer::newConnection, [=]() {
    QTcpSocket *clientSocket = tcpServer->nextPendingConnection();
    QObject::connect(clientSocket, &QTcpSocket::readyRead, [=]() {
        qDebug() << clientSocket->readLine();

    });
});

0 个答案:

没有答案