Http get request : no body in webassembly
-
wrote on 21 Aug 2020, 14:47 last edited by
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 -
@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 ?
wrote on 24 Aug 2020, 14:20 last edited by@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." -
wrote on 24 Aug 2020, 13:33 last edited by
You need to use something like websockify or configure CORS. You cannot make requests to any destination just like that.
-
wrote on 24 Aug 2020, 13:43 last edited by Mixlu
@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?
-
@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?
wrote on 24 Aug 2020, 13:46 last edited by@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?
-
@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?
wrote on 24 Aug 2020, 13:52 last edited by Mixlu@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 usingmanager->sendCustomRequest(...)
-
@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 usingmanager->sendCustomRequest(...)
wrote on 24 Aug 2020, 14:02 last edited by@Mixlu I understand. I would rather investigate Fetch API or CURL. I used both successfully just yesterday. Otherwise you might file a bug.
-
wrote on 24 Aug 2020, 14:06 last edited by
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.
-
wrote on 24 Aug 2020, 14:10 last edited by Mixlu
@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 ?
-
@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 ?
wrote on 24 Aug 2020, 14:20 last edited by@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." -
@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."wrote on 24 Aug 2020, 14:24 last edited by@Ahmed-Yarub-Hani-Al-Nuaimi Oh ok I see, thanks for your time !
2/10