google-chromegoogle-chrome-devtoolscorsplayframework-2.1

Android Chrome, CORS and Play!Framework fails


I've built a web application using CORS for communicating with the API.

The API accept all origin and some headers and is written using Play!Framework.

On every request made to the app, I add these headers :

  override def doFilter(action: EssentialAction): EssentialAction = EssentialAction { request =>
    action.apply(request).map(_.withHeaders(
      "Access-Control-Allow-Origin" -> "*",
      "Access-Control-Allow-Methods" -> "GET, POST, PUT, DELETE, OPTIONS",
      "Access-Control-Allow-Headers" -> "Origin, X-Requested-With, Content-Type, Accept, Host, Api-Token"
    ))
  }

Everything works great in Firefox and Chrome in the desktop (tested under Windows and Linux), but fails on my Android phone (using Chrome browser and the native browser).

I enabled the Chrome debugging via USB, and I can clearly see that Chrome doesn't go further than the OPTIONS request made to the server. Here's the request made :

Request URL:http://127.0.0.1:9100/auth/login
Request Headersview source
Access-Control-Request-Headers:accept, origin, x-requested-with, content-type
Access-Control-Request-Method:POST
Origin:http://192.168.0.15:9000
Referer:http://192.168.0.15:9000/login
User-Agent:Mozilla/5.0 (Linux; Android 4.1.1; HTC One S Build/JRO03C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Mobile Safari/537.36

And it stops here, no response from the server (but the Network tabs indicate "Pending" for this request !).

So now I don't know what is wrong. How can I fix this problem ?


Solution

  • It may be a red herring, but I see in the headers you show the string:

    Request URL:http://127.0.0.1:9100/auth/login
    

    It seems to me that it tries to connect to localhost (127.0.0.1) but your mobile doesn't have a running server, so it fails.