Search code examples
phpmysqlangularjsionic-frameworkhybrid-mobile-app

Ionic/Angular $http.get returning Response for preflight has invalid HTTP status code 404


I am developing an application in IONIC. I am making a $http.get request in Angular JS and its giving me 404 error when I successfully login and trying to load the user profile using the token sent in the authentication header.

It produces error in chrome, although I enabled CORS. Please check the screenshot:


screenshot

Now if I try the url in POSTMAN, everything is ok. See the screenshot below:

screenshot 2

I am stuck with this error, can someone help me?


Solution

  • What Ionic says

    There are two ways to solve the issue: The first, and easier, solution is to just allow all origins from your API endpoint. However, we can’t always control the endpoint we are accessing. What we need, then, is a request that does not specify an origin.

    We can do this by using a proxy server. Let’s look how the Ionic CLI provides

    Reference

    What works but isn't completely good to use

    A simple solution is just add a CORS plugin into your browser and everything will work.

    Plugin Link

    Proxy server

    If you want a proxy server there is this tutorial:

    Link