TWebHttpRequest

I have a TWebHttpRequestand I have handlers for OnAbort, OnRequestResponse, OnResponse and OnTimeOut. I am calling a local test server (WebBroker). If I call it either directly from the browser, or from a VCL Test app using a TRESTClient/TRESTRequest, I get the correct reponse. When I call it from the WebHttpRequest I get nothing, not even a timeout with the timeout period set to 10 ms. The server logs calls it receives, but logs nothing from the TWebHttpRequest. It appears that it simply does not work at all, so does anyone have any ideas please. Delphi 10.3.3 (Rio) / WebCore 1.3.3.0.

As far as I can tell TWebHttpRequest works correctly. 

Did you look into the browser console for errors (for the typical CORS error?) ?

Hi,

I found this thread while searching for answers about a similar problem I have. WebHttpRequest mostly works fine when running on a local test environment (laragon), but when tested on a proper server it only gets empty responses, the request being cancelled for no clear reason.

It bogged me for a while, then I looked at HTTP headers in plain text and noticed that the header started as "GET /api.php?from=0 undefined" instead of, say "GET /api.php?from=0 HTTP/1.1"

So, the problems seems to be the missing protocol.

Does anybody have the same issue ? Any known workaround ?

Great thanks, and have a nice day.

PS : same erroneous behavior occurs localy but rarely.

The browser chooses itself what protocol to use. I cannot think this being the reason.
What exact error message do you see in the browser console?

The browser explanation would be even stranger, as I use the same browsers to test localy and remotely.

I have no error in the console, just no data, and I have to look at the network informations to get some clues.

It's also unlikely that the php scipt is responsible for the issue, since I get exactly the same behavior using the URL of a static json file.

Thanks a lot for your help, Bruno, and also for the great product :+1:

BTW I just noticed that my local server is HTTP/1.1 but all my remote ones are using HTTP/2.

It is unclear what is causing this. I cannot immediately see our TWebHttpRequest component would do something wrong. It is a fairly thin & simple wrapper around the JavaScript function XMLHttpRequest


You could check if directly calling this JavaScript function yields a different result?

I made the text and the manual JS call works fine : I get my datas!

Here are the request headers in both cases, native JS call first, then TMSWC :

GET /api.php?from=0 HTTP/2
Host: XXXXXXXXiel.net
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
Accept: /
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
DNT: 1
Connection: keep-alive
Referer: https://XXXXXXXXiel.net/
Pragma: no-cache
Cache-Control: no-cache

POST /api.php?from=0 undefined
Host: XXXXXXXXiel.net
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
Accept: /
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Origin: https://XXXXXXXXiel.net
DNT: 1
Connection: keep-alive
Referer: https://XXXXXXXXiel.net/
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 0

The test was made with "pure JS" in a in the page source.
Later I'll try with the code in an asm block.

I do not understand how you compare these. The first request appears to be a HTTP GET and the second appears to be a HTTP POST.
For a correct comparison, I would think you need both HTTP GET or both HTTP POST.
If a problem persists, can you provide the JavaScript code you use and the Delphi code you use so we can reproduce this here and investigate?

Yes, it's a POST request, but headers and result areexactly the same as the GET one (no data posted). I just made this test after the GET test to see if that would change a thing. The headers are the same as with GET (except for the method and content-length header of course).

I'll try to make a basic project to seeif I can reproduce this, and I'll let you know and post it here if yes.

I tried a lot of things to isolate the source oif the problem, without success. Finaly i removed some logging before and after the call to Execute()... and the bug disapeared! I put back the logging calls, but the bug never came back. I gess this will remains a mystery...

Thanks, and sorry for the wasted time.