Unable to access web application rest service from ionic app

Getting preflight issue, when accessing a php web app rest service using http.post from ionic app, but http.post is working from postman client. http.get is working from ionic app. Please help me to figure out the issue.

It gives any error issues when running on your app? Please post your error console logs

i thing add additional config on your php server…

Below i have pasted the console error.

XMLHttpRequest cannot load https://domain/api/vehicle. Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.

My back end api application is laravel. Which is hosted in heroku server. http.get is return the response properly.

Yes of course http.get is properly working. but http.post needs some config on your php API files. i don’t knew where is our code should be putting. but i give asp.net config

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
GlobalConfiguration.Configuration.Formatters.Remove(GlobalConfiguration.Configuration.Formatters.XmlFormatter);
}
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains(“Origin”) && Request.HttpMethod == “OPTIONS”)
{
Response.Flush();
}
}
protected void Application_BeginRequest(Object sender, EventArgs e)
{
//HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Origin”, “*”);
if (HttpContext.Current.Request.HttpMethod == “OPTIONS”)
{
// HttpContext.Current.Response.AddHeader(“Cache-Control”, “no-cache”);
// HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Methods”, “GET, POST”);
// HttpContext.Current.Response.AddHeader(“Access-Control-Allow-Headers”, “Content-Type, Accept”);
// HttpContext.Current.Response.AddHeader(“Access-Control-Max-Age”, “1728000”);
// HttpContext.Current.Response.End();
}
}

this is my global.aspx file

This is cors.php file.

return $next($request)
->header(‘Access-Control-Allow-Origin’, ‘*’)
->header(‘Access-Control-Allow-Methods’, ‘GET, POST, PUT, DELETE, OPTIONS’)
->header(‘Access-Control-Allow-Headers’, ‘Origin, Content-Type, Accept, Authorization, X-Requested-With’);

can you please tell me anything else i need to add ?.

have you any other configuration files… ex in ASP.NET web.config…

this is very easy…

this type of issues were came in ionic 2

Yes. I have web.config file, which is in xml format.

Make your /api/vehicle endpoint respond with a ‘Access-Control-Allow-Origin’ header to preflight requests.
To understand better what request exactly is meant, look at the requests your app is sending before this error happens.