score:2

Accepted answer

this is play framework issue with cordova. the following link will explain it:

https://forum.ionicframework.com/t/ionic-http-request-with-403-error-on-ipad-device/50269/3

reason:

cordova sends a request through having header origin: file://…

you can check this link to deal with that play! 2.4: how to allow cors from origin file://

remove default course filter which you import from play framework and write your condition based filter:

import play.api.logger
import play.api.libs.concurrent.execution.implicits.defaultcontext
import play.api.mvc._
import play.mvc.http

/**
  * allow cors from anywhere, any method
  */
class corsfilter extends essentialfilter {
  def apply(nextfilter: essentialaction) = new essentialaction {
    def apply(requestheader: requestheader) = {
      nextfilter(requestheader)
        .map { result =>
          if (requestheader.method.equals("options")) {
            results.ok.withheaders(
              http.headernames.access_control_allow_origin -> "*",
              http.headernames.access_control_allow_headers -> "access-control-allow-origin,x-requested-with, accept, content-type,application, iduser, access-control-allow-methods, token, access-control-allow-credentials, authorization",
              http.headernames.access_control_allow_methods -> "head,get,post,put,patch,delete")
          } else {
            result.withheaders(
              http.headernames.access_control_allow_origin -> "*",
              http.headernames.access_control_allow_headers -> "x-requested-with, accept, content-type",
              http.headernames.access_control_allow_methods -> "head,get,post,put,patch,delete",
              http.headernames.access_control_expose_headers -> "x-custom-header-to-expose")
          }
        }
    }
  }
}

Related Query

More Query from same tag