3
I am creating a Delphi Rest Full server to be accessed with Angular front-end, I can apply the POST, PUT and GET but in the attempt to run a DELETE I get the CORS error implemented treatment as many examples of the internet but without success. how should I proceed to resolve DELETE??
Access to Xmlhttprequest at 'http://localhost:8888/datasnap/Rest/apiPais/Pais/2' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
procedure TWebModule1.WebModuleBeforeDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
// Response.SetCustomHeader('Access-Control-Allow-Origin','*');
Response.CustomHeaders.Values['Access-Control-Allow-Origin'] := '*';
Response.CustomHeaders.Values['Access-Control-Allow-Credentials'] := 'true';
Response.CustomHeaders.Values['Access-Control-Allow-Methods'] := 'GET, POST, PUT, DELETE, OPTIONS';
if Trim(Request.GetFieldByName('Access-Control-Request-Headers')) <> '' then
begin
Response.SetCustomHeader('Access-Control-Allow-Headers', Request.GetFieldByName('Access-Control-Request-Headers'));
Handled := True;
end;
if FServerFunctionInvokerAction <> nil then
FServerFunctionInvokerAction.Enabled := AllowServerFunctionInvoker;
end;
What is the HTTP status of pre-flight? It should be 200.
– aledpardo
You managed to solve @Ailton
– aledpardo
Friend... I tried everything that was literature about, I followed examples but it doesn’t work... I tried to find your email for a PVT but without success... if you can help me thank (ps - I don’t even know if I can make this kind of request here, but if you can follow my email [email protected])
– Ailton Branco
Add question the results of DELETE request.
– aledpardo
From the error, it seems that the problem is that your server is not responding to the preflight with a 200...
– Felipe Avelar
so this answer that I don’t know how to implement... I was able to solve everything but him
– Ailton Branco