Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there HTTP parser?
Forum Updated to NodeBB v4.3 + New Features

Is there HTTP parser?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subuday
    wrote on last edited by Subuday
    #1

    Hi, I didn't find any ways to parse HTTP request on my server. I use QNetworkRequest on client side, then it is sended to server. I get only QByteArray on server which I can only convert to QString. (Maybe I am wrong, but I didn't find more information) So how to parse QString? Also, I need to do it without using third-party libraries and frameworks! Check my code below.

    //Client request

        const QUrl url = QUrl("http://localhost:8080/");
        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0");
        QNetworkReply *reply = manager->get(request);
    

    // Server side

    
    void Runnable::run()
    {
        if(!socketDescriptor) return;
    
        QTcpSocket socket;
        socket.setSocketDescriptor(socketDescriptor);
    
        socket.waitForReadyRead();
        qDebug() << socket.readAll();
    
        socket.close();
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Depending on what you want to do, the cutelyst project might be interesting.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Depending on what you want to do, the cutelyst project might be interesting.

        S Offline
        S Offline
        Subuday
        wrote on last edited by
        #3

        @SGaist Unfortunately, I can't use third-party libraries and framewroks.

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          That is what the HTTP protocol does. You send it something it returns something else, or it returns an error. The client sent something to the server. You will need to determine what to send to the client based upon what the client sent. You will have to research the HTTP protocol to determine the appropriate responses to various data requests.

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Does Qt-labs projects also count as third party ? If not then you should check https://code.qt.io/cgit/qt-labs/qthttpserver.git/

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            2
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by fcarney
              #6

              https://developer.mozilla.org/en-US/docs/Web/HTTP/Overview

              Edit: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
              This page references the current standards governing HTTP protocol. It will give you a place to lookup what a message should look like and what a response should look like. It will also give you the codes needed for errors and such. I think implementing a small subset it probably what you are looking for.

              I am actually surprised there isn't an example in Qt Creator on how to make a server. I did see a note that the link @SGaist provided would eventually be included in Qt. You could learn from that project at the very least. To see how they structure the code.

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              1
              • SGaistS SGaist

                Does Qt-labs projects also count as third party ? If not then you should check https://code.qt.io/cgit/qt-labs/qthttpserver.git/

                S Offline
                S Offline
                Subuday
                wrote on last edited by
                #7

                @SGaist Yes, It is forbidden

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Then at least you can get some inspiration from that module to implement yours.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved