androidioshttpcaptivenetworkcaptiveportal

What response is required for captive portal to appear?


I am trying to implement captive portal on a small embedded device.

As I understand all I need is to capture smartphone requests to special urls and send response containing captive portal page. In order not to maintain list of all the possible URLs I have set up a DNS which resolves all the hosts to my device IP.

Now when I connect android device to my network, I catch a request to /generate_204 and send redirect response. Here is an example of a request and response from curl command:

curl -v http://google.com/generate_204 

*   Trying 192.168.1.1...
* Connected to google.com (192.168.1.1) port 80 (#0)
> GET /generate_204 HTTP/1.1
> Host: google.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Content-Type: text/html
< Content-Length: 0
< Location: /
< 
* Connection #0 to host google.com left intact

Using Postman/Chrome I am redirected to a 192.168.1.1/ and required page is loaded. However I tested 4 android devices and only one showed me a popup. Same problem with ios. I catched a request to /hotspot-detect.html returned the same response as above and nothing happened. What am I missing here?

Thanks!


Solution

  • I found an answer. Location header in redirect response must look differently. In particular:

    Location: http://192.168.1.1/
    

    This solves the issue.