When TWebHttpRequest is not working as expected

When TWebHttpRequest is not working as expected, the first thing to do is inspect the browser console. It typically contains more detailed information about the exact cause & circumstances of the problem.

When TWebHttpRequest is not working as expected, it is 9 out of 10 times the dreaded CORS issue.
HTTP requests performed from JavaScript code in the web browser behave slightly different than HTTP requests executed from a native application or directly via opening a URL in the browser.
The typical reaction is: but it works in Postman, but it works when opening the URL in the browser, but it works when I used it from my VCL app....
Yes, it is perfectly possible your HTTP(s) requests work from another application but NOT when performed via code in a web client application and it is because of CORS.

If you are serious about web development, you should familiarize yourself with what CORS is.
Two good resources are:

The solution to a CORS issue is server-side! It is the server that denies the preflight check from the TWebHttpRequest from the browser, so it is server side this needs to be handled. How to do this will depend on the server technology you use.

If your backend server is created with TMS XData, check:

If you use Embarcadero RAD server, check:

and the setting "Access-Control-Allow-Origin"

If you use a service on IIS, check:

Finally, here are more references for enabling CORS on various other servers:

1 Like