CORS policy Delphi Rest Full

Asked

Viewed 475 times

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.

  • You managed to solve @Ailton

  • 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])

  • Add question the results of DELETE request.

  • From the error, it seems that the problem is that your server is not responding to the preflight with a 200...

  • so this answer that I don’t know how to implement... I was able to solve everything but him

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.