511 Network Authentication Required
Fault: Neither
TL;DR
Network authentication required (captive portal).
The client needs to authenticate to gain network access.
What This Error Means
The client needs to authenticate to gain network access.
Network authentication required (captive portal).
Common Causes
- Captive portal at hotel/airport
- Public Wi-Fi authentication
- Network access control
How to Fix It (For Visitors)
- Open browser to authenticate
- Complete captive portal login
- Agree to terms of service
How to Fix It (For Developers/Admins)
- Implement captive portal detection
- Handle authentication flow
- Redirect to login page
Code Examples
Here's how to return a 511 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Network Authentication Required"}), 511
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(511).json({ message: 'Network Authentication Required' });
});
PHP
<?php
http_response_code(511);
header('Content-Type: application/json');
echo json_encode(['message' => 'Network Authentication Required']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(511)
json.NewEncoder(w).Encode(map[string]string{
"message": "Network Authentication Required",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Network Authentication Required");
return ResponseEntity.status(511).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 511
json message: 'Network Authentication Required'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 6585.