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

Thank you for the reply and I take on-board any potential cors errors, however in this instance I am calling the exact same api service function (xdata) that successfully returns the json every time (can call it several hundred times and get the expected json response) and can display it, it is when it tries to populate the dataset is when the issue appears.

I will look into any cors issue, but I don't think cors is my issue at this time.

Richard

We would really need to know more details before we can say anything sensible to this.