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. Prevent multiple TCP segments in post request
Qt 6.11 is out! See what's new in the release blog

Prevent multiple TCP segments in post request

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 5 Posters 5.1k 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.
  • V vicsoftware

    Simple curl code works:

    const std::string url{ "http://" + m_addr + "/od/2400/01" };
            CURL *curl;
            CURLcode res;
    
            curl_global_init(CURL_GLOBAL_ALL);
    
            curl = curl_easy_init();
            if(curl) {
                curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "\"00000001\"");
    
                res = curl_easy_perform(curl);
                if(res != CURLE_OK)
                    fprintf(stderr, "curl_easy_perform() failed: %s\n",
                            curl_easy_strerror(res));
    
                curl_easy_cleanup(curl);
            }
            curl_global_cleanup();
    

    QNetworkManager post failed.

    JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #21

    @vicsoftware
    Two comments:

    • As @Christian-Ehrlicher has said, you need to produce (minimal, test) Qt code, not curl code, if you want someone to look at it as a Qt issue.

    • You, and your program, are never supposed to care what is going on at the TCP packet level. Whether an application makes a request which gets passed as one TCP packet, or two, or other, should have no effect. We have all used TCP for years, with Qt or other toolkits, and never cared about this or noticed any behaviour such as you report with "errors" occurring. Again, for the record, it is basically down to the OS/TCP level how it chooses to packet-ise messages. Artefacts such as Nagle's algorithm will commonly affect the runtime packet behaviour.

    V 1 Reply Last reply
    0
    • J.HilkJ J.Hilk

      @vicsoftware why do you post the code that "works" for you and not the one that doesn't!?!?!

      V Offline
      V Offline
      vicsoftware
      wrote on last edited by vicsoftware
      #22

      @J-Hilk QT code posted above.

      1 Reply Last reply
      0
      • JonBJ JonB

        @vicsoftware
        Two comments:

        • As @Christian-Ehrlicher has said, you need to produce (minimal, test) Qt code, not curl code, if you want someone to look at it as a Qt issue.

        • You, and your program, are never supposed to care what is going on at the TCP packet level. Whether an application makes a request which gets passed as one TCP packet, or two, or other, should have no effect. We have all used TCP for years, with Qt or other toolkits, and never cared about this or noticed any behaviour such as you report with "errors" occurring. Again, for the record, it is basically down to the OS/TCP level how it chooses to packet-ise messages. Artefacts such as Nagle's algorithm will commonly affect the runtime packet behaviour.

        V Offline
        V Offline
        vicsoftware
        wrote on last edited by
        #23

        @JonB I have nanotec.com tcp controller C5-E-2-81. It has REST API to control driver. So i can only get/post. And i can't reproduce for you it. You do not have that controller.
        I tried online service and it works. But that service do not dispatch input data, it only receives post so it is not the same as controller.

        In this case, the question is why all other methods do but QT does not? It simple post but it does not work.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #24

          Why does your curl data, "\"00000001\"=" and Qt data, "\"00000002\"" both have a content length of '10' (at least that's what you put in the request header for both)? Will you ever include a 'value' with your form request (i.e., don't form requests usually consist of key-value pairs)?

          V 1 Reply Last reply
          0
          • M mchinand

            Why does your curl data, "\"00000001\"=" and Qt data, "\"00000002\"" both have a content length of '10' (at least that's what you put in the request header for both)? Will you ever include a 'value' with your form request (i.e., don't form requests usually consist of key-value pairs)?

            V Offline
            V Offline
            vicsoftware
            wrote on last edited by vicsoftware
            #25

            @mchinand Yes. It is only key value of 10bytes without value. Such controller REST API and recommendations from developers. Digit does not matter.

            M 1 Reply Last reply
            0
            • V vicsoftware

              @mchinand Yes. It is only key value of 10bytes without value. Such controller REST API and recommendations from developers. Digit does not matter.

              M Offline
              M Offline
              mchinand
              wrote on last edited by
              #26

              @vicsoftware said in Prevent multiple TCP segments in post request:

              @mchinand Yes. It is only key value of 10bytes without value. Such controller REST API and recommendations from developers. Digit does not matter.

              Right, but the length of the data strings is not the same yet you set the same content-length in the header for both of them.

              V 1 Reply Last reply
              0
              • M mchinand

                @vicsoftware said in Prevent multiple TCP segments in post request:

                @mchinand Yes. It is only key value of 10bytes without value. Such controller REST API and recommendations from developers. Digit does not matter.

                Right, but the length of the data strings is not the same yet you set the same content-length in the header for both of them.

                V Offline
                V Offline
                vicsoftware
                wrote on last edited by
                #27

                @mchinand All working cases have string with 10 bytes length. Can you provide example of your idea?

                M 1 Reply Last reply
                0
                • V vicsoftware

                  @mchinand All working cases have string with 10 bytes length. Can you provide example of your idea?

                  M Offline
                  M Offline
                  mchinand
                  wrote on last edited by
                  #28

                  @vicsoftware said in Prevent multiple TCP segments in post request:

                  @mchinand All working cases have string with 10 bytes length. Can you provide example of your idea?

                  from your post above:
                  curl -X POST -d "\"00000001\"="
                  and
                  QString data{ "\"00000002\"" };

                  V 1 Reply Last reply
                  0
                  • M mchinand

                    @vicsoftware said in Prevent multiple TCP segments in post request:

                    @mchinand All working cases have string with 10 bytes length. Can you provide example of your idea?

                    from your post above:
                    curl -X POST -d "\"00000001\"="
                    and
                    QString data{ "\"00000002\"" };

                    V Offline
                    V Offline
                    vicsoftware
                    wrote on last edited by vicsoftware
                    #29

                    @mchinand
                    Content length used by REST API to extract string from data.

                    So first 10 bytes of these lines will have same content?
                    curl -X POST -d "\"00000001\""
                    and
                    QString data{ "\"00000001\"" };

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vicsoftware
                      wrote on last edited by
                      #30

                      Here is from controller manual:

                      Screenshot from 2021-10-13 00-41-03.png

                      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