Load local json config file, 403 cors error

I want to load my config from a local json file. There are the settings for my rest server.
But I get an 403 error.
See picture.
Here is the code in Delphi:

  Conn: TXDataWebConnection;
  Conn := TXDataWebConnection.Create(nil);
    Conn.SendRequest(THttpRequest.Create('config/config.json'), THttpResponseProc( @OnSuccess), THttpErrorProc( @OnError));

What can I do?


The file is not local to the PC. It is of course on the server in the specified folder.
But on the same server as the html files.

It is not cross domain. And it is not a call to my own XData server.
I want only load a config file from the server.

On Windows, we have ini files for the config. But for WebCore we need something else.

I have used the example from XDataMusicWeb-Demo.

I think, I have to config my Webserver
But what do I have to do there?

I've done something like this in my projects.

procedure TMainForm.LoadConfig;
  Request: TWebHTTPRequest;       // The request/URL
  Response: TJSXMLHttpRequest;    // The response coming back
  Data: TJSONObject;              // The response coming back, as JSON
    Request := TWebHTTPRequest.Create;
    Request.URL := '...server url from same host.../config.json';
    Response := await(TJSXMLHttpRequest,Request.Perform());
    Data := TJSONObject.ParseJSONValue(String(Response.Response)) as TJSONObject;
    ...do something with data...

This assumes that just typing the URL into your browser will load the config file. If it doesn't, you might want to get that sorted out first.

Thank you, Andrew.
This is roughly the same.
And I get the same error.
A CORS setting is missing. But I don't know where.

Your server is not responding with any CORS headers, such as access-control-allow-origin. We can't see if it's a problem with CORS because there is no URLs in your screenshots, but your server doesn't look to be configured to support CORS.

Also, what do you have in the response body?

Yeah, just accessing https://zaboric.info/Admin/config/config.json from a browser generates a 403 all on its own, but https://zaboric.info/Admin/admin.html works fine. So it could just simply be that the web server doesn't have permission to access the config folder, or even the config.json file itself?

I have tried by myself to edit the httpd.conf on the server.
I insert

Header set Access-Control-Allow-Origin "https://meinedomain.de"

But this is not all, I think. It doesn't work.
I must wait for my Webserver admin and ask for cors.

First solution:

I have renamed the file




Probably .txt types are released and .json types are not.

Everything else must now be done by a web server administrator.

Thank you all

What I wanted to say:
ChatGPT has found the solution.
The AI said I should check the mime type and add application/json.

If it is of interest, what was the question and what was the answer.
Here is a screenshot in German and English

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.