-1

I am sending form data to a api which is running in python flask. The form is in angular 11. When using httpclient the api is not accessible.

this.http.post('http://192.168.0.95:5001/login', formData).subscribe(

  (response) => console.log(response),
  (error) => console.log(error)
)

But when i directly submit the form to that api its working.

<form action ="http://192.168.0.95:5001/login">

I have updated the proxy.conf.json file as below

{
    "/": {
        "target": "http://localhost:3000",
        "secure": false,
        "logLevel": "debug"
    }
}

but its not working. Anyone please help with this

Dinesh D
  • 79
  • 3
  • 13
  • That proxy config doesn't make sense; it doesn't have the right target, and given that you're making the requests directly to the target the proxy won't get hit anyway. – jonrsharpe Dec 24 '20 at 10:02
  • Does this answer your question? [Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – Delwyn Pinto Dec 24 '20 at 10:33

1 Answers1

-1

By default browser will block cross platform request. You need to configure access on server.

For more details please check this: https://www.techiediaries.com/fix-cors-with-angular-cli-proxy-configuration/ https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sachin Karche
  • 121
  • 1
  • 9