Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Http get request : no body in webassembly
QtWS25 Last Chance

Http get request : no body in webassembly

Scheduled Pinned Locked Moved Solved Qt for WebAssembly
wasmhttphttp getemscripten
10 Posts 2 Posters 3.1k Views
  • 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.
  • M Offline
    M Offline
    Mixlu
    wrote on 21 Aug 2020, 14:47 last edited by
    #1

    Hi,

    I want to make a simple HTTP GET request to an API with a simple body.
    Here is how I did it:

    QUrl url("http://192.168.30.222:3000");
    QNetworkAccessManager* manager = new QNetworkAccessManager();
    
    QNetworkRequest request;
    request.setUrl(url);
    
    QObject::connect(manager, &QNetworkAccessManager::finished, this, [ = ](QNetworkReply * reply)
    {
        qDebug() << "reply: " <<  reply->readAll();
    });
    
    QByteArray bodyData = "BODY DATA";
    
    manager->sendCustomRequest(request, "GET", bodyData);
    

    It is working perfectly under MinGW (Windows), I started Wireshark and saw the "BODY DATA".
    But when I compile the project for WebAssembly and make the request with the same project, the body content disappears.

    I am using:
    Qt: 5.14.2
    MinGW: 7.3.0
    Emscripten: sdk-fastcomp-1.38.27-64bit

    1 Reply Last reply
    0
    • M Mixlu
      24 Aug 2020, 14:10

      @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

      You cannot send a body with a GET request!

      Yes it's not really common but why not? The http protocol allow it and the QNetworkAccessManager->sendCustomRequest(...) seems to permit it.

      It is a webassembly restriction ?

      A Offline
      A Offline
      Ahmed Yarub Hani Al Nuaimi
      wrote on 24 Aug 2020, 14:20 last edited by
      #9

      @Mixlu I guess that QUrl is using Fetch API, which in turn (I think) uses XHR. I think that it's a browser restriction. Ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
      "If the request method is GET or HEAD, the body parameter is ignored and the request body is set to null."

      M 1 Reply Last reply 24 Aug 2020, 14:24
      2
      • A Offline
        A Offline
        Ahmed Yarub Hani Al Nuaimi
        wrote on 24 Aug 2020, 13:33 last edited by
        #2

        You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mixlu
          wrote on 24 Aug 2020, 13:43 last edited by Mixlu
          #3

          @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

          You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.

          CORS is configured on my server side to accept all type of request. Do I need to configure something on the client side (here) also?

          A 1 Reply Last reply 24 Aug 2020, 13:46
          0
          • M Mixlu
            24 Aug 2020, 13:43

            @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

            You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.

            CORS is configured on my server side to accept all type of request. Do I need to configure something on the client side (here) also?

            A Offline
            A Offline
            Ahmed Yarub Hani Al Nuaimi
            wrote on 24 Aug 2020, 13:46 last edited by
            #4

            @Mixlu said in Http get request : no body in webassembly:

            @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

            You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.

            CORS is configured on my server side to accept all type of request. Do I need to configure something on the client side (here) also?

            Is your Qt app hosted on the same IP and port? I mean in the browser you access it from the same IP?

            M 1 Reply Last reply 24 Aug 2020, 13:52
            0
            • A Ahmed Yarub Hani Al Nuaimi
              24 Aug 2020, 13:46

              @Mixlu said in Http get request : no body in webassembly:

              @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

              You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.

              CORS is configured on my server side to accept all type of request. Do I need to configure something on the client side (here) also?

              Is your Qt app hosted on the same IP and port? I mean in the browser you access it from the same IP?

              M Offline
              M Offline
              Mixlu
              wrote on 24 Aug 2020, 13:52 last edited by Mixlu
              #5

              @Ahmed-Yarub-Hani-Al-Nuaimi No, I access the Qt app from a different IP.

              But it works well with other request, I am able to send simple HTTP GET/POST request with manager->get(...), manager->post(...)
              It seems that the error only appear when I am using manager->sendCustomRequest(...)

              A 1 Reply Last reply 24 Aug 2020, 14:02
              0
              • M Mixlu
                24 Aug 2020, 13:52

                @Ahmed-Yarub-Hani-Al-Nuaimi No, I access the Qt app from a different IP.

                But it works well with other request, I am able to send simple HTTP GET/POST request with manager->get(...), manager->post(...)
                It seems that the error only appear when I am using manager->sendCustomRequest(...)

                A Offline
                A Offline
                Ahmed Yarub Hani Al Nuaimi
                wrote on 24 Aug 2020, 14:02 last edited by
                #6

                @Mixlu I understand. I would rather investigate Fetch API or CURL. I used both successfully just yesterday. Otherwise you might file a bug.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Ahmed Yarub Hani Al Nuaimi
                  wrote on 24 Aug 2020, 14:06 last edited by
                  #7

                  Oh now I see it! You cannot send a body with a GET request! If you are changing something you'll have to send POST.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mixlu
                    wrote on 24 Aug 2020, 14:10 last edited by Mixlu
                    #8

                    @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

                    You cannot send a body with a GET request!

                    Yes it's not really common but why not? The http protocol allow it and the QNetworkAccessManager->sendCustomRequest(...) seems to permit it.

                    It is a webassembly restriction ?

                    A 1 Reply Last reply 24 Aug 2020, 14:20
                    0
                    • M Mixlu
                      24 Aug 2020, 14:10

                      @Ahmed-Yarub-Hani-Al-Nuaimi said in Http get request : no body in webassembly:

                      You cannot send a body with a GET request!

                      Yes it's not really common but why not? The http protocol allow it and the QNetworkAccessManager->sendCustomRequest(...) seems to permit it.

                      It is a webassembly restriction ?

                      A Offline
                      A Offline
                      Ahmed Yarub Hani Al Nuaimi
                      wrote on 24 Aug 2020, 14:20 last edited by
                      #9

                      @Mixlu I guess that QUrl is using Fetch API, which in turn (I think) uses XHR. I think that it's a browser restriction. Ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
                      "If the request method is GET or HEAD, the body parameter is ignored and the request body is set to null."

                      M 1 Reply Last reply 24 Aug 2020, 14:24
                      2
                      • A Ahmed Yarub Hani Al Nuaimi
                        24 Aug 2020, 14:20

                        @Mixlu I guess that QUrl is using Fetch API, which in turn (I think) uses XHR. I think that it's a browser restriction. Ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
                        "If the request method is GET or HEAD, the body parameter is ignored and the request body is set to null."

                        M Offline
                        M Offline
                        Mixlu
                        wrote on 24 Aug 2020, 14:24 last edited by
                        #10

                        @Ahmed-Yarub-Hani-Al-Nuaimi Oh ok I see, thanks for your time !

                        1 Reply Last reply
                        0

                        4/10

                        24 Aug 2020, 13:46

                        • Login

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