What response is required for captive portal to appear?

2.3k Views Asked by At

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!

2

There are 2 best solutions below

1
Long Smith On BEST ANSWER

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

Location: http://192.168.1.1/

This solves the issue.

4
LavaSlider On

It is my understanding that if you return anything other than what the captive specific portal test site returns (i.e., what http://google.com/generate_204 returns if that was the requested URI or what http://captive.apple.com//hotspot-detect.html returns if that was the requested URI) then what you return will be displayed, the so-called splash screen. Returning what these URLs return should suppress the splash screen and fool the device into thinking it is connected to the Internet.