I have a URL that works in my browser and in the RESTDebugger. However, I am not able to get it to work in my WebCore-Project. All I get is an error message at the bottom containing "FJSError::Error: HTTP request error". The URL should return some JSON.
This is what I want to do
procedure TForm1.TMSFNCButton1Click(Sender: TObject);
WebHttpRequest1.URL := '....';
procedure(AResponse: string; AReq: TJSXMLHttpRequest)
// parsing JSON
The given URL above requires authentication via a parameter of type header. I added this in the headers property, but in vain. What am I missing?
Ok, seems to be a CORS problem. However, Access-Control-Allow-Origin - where do I specify this in my WebHTPRequest?
The REST-Debugger as well as the browser can access the RESt service. What am I missing in to WebHTTPRequest?
I see. RTFM. I thought, CORS might be a common pitfall when it comes to TMS-WebCore, so I asked.
In the meanwhile I learned a bit. The TMS-WebCore-pages need the TMS-WebCore Server when run locally. This server tries to contact the REST-API and this causes the CORS problems, because this is cross server scripting which is considered harmful. Neither my local EXE nor my local browser do cross server scripting when accesing the API so no poblem there. As you said, CORS needs to be solved on server side, where my API resides. Solvable problem, I think. Tx.
The TMS WEB Core web client app performs the HTTP requests to the REST API directly from the browser. It's not going via the (local debug) webserver the app is started from. You give no information about your REST server and what technology is used for the REST server. But it is in your REST server you'll need to enable CORS.
Also, when encountering problems, open a browser console (F12 shortcut) as there will be more detail about possible errors there.