Problem CORS Angular + Protheus

Asked

Viewed 597 times

1

I’ve looked in some places and I can’t find anything about it, I’d like to know if anyone’s been through it and can help me.

I am trying to make a REST request through an Angular application running on port 4200 (localhost:4200), to the Protheus server on port 9094 (localhost:9094/Rest/method).

However, the destination method returns with status 200, and the response from the right server, but is giving the error:

" Access to Xmlhttprequest at 'http://localhost:9094/Rest/method? mat=123123&pwd=123123' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested Resource. "

I have already tried to release in Protheus appserver.ini to accept CORS from any source, and I don’t know what else can be.

inserir a descrição da imagem aqui

  • 1

    You can add the CORS configuration in appserver.ini in the question?

  • Of course, I’ve already added to the question, thank you!

  • I was able to find a solution by researching a little more and I was able to make the request, but I’m not sure if this would be the definitive solution. It was necessary to configure a proxy in the application: https://medium.com/@gigioSouza/solving-the-problem-do-Cors-with-angular-2-e-o-angular-cli-7f7cb7aab3c2

  • Good afternoon! You saw this: https://medium.com/@adrianonegrao/enable-Cors-to-access-servi%C3%A7os-Rest-e6a3a11db182 https://medium.com/@alexandremjacques/understanding-o-Cors-parte-8331d0a777e1

1 answer

0

Good afternoon.

Place this line at the beginning of your REST/ADVPL service:

::SetHeader('Access-Control-Allow-Credentials' , "true")

Abs.

  • Thanks for the help, but not for sure, I decided to create a proxy. https://medium.com/@gigioSouza/solving-the-problem-do-Cors-with-angular-2-e-o-angular-cli-7f7cb7aab3c2

Browser other questions tagged

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