Example HTTP Response
HTTP/1.1 511 Network Authentication Required
Content-Type: text/html
<html><body>Please log in to access the network</body></html>- Captive portal requiring login
- Network access requires authentication
- Hotel or airport Wi-Fi gateway
What does this mean?
Wi-Fi login time! You've connected to a network that wants you to sign in first. Usually that annoying coffee shop or airport portal.
Technical Definition
The client needs to authenticate to gain network access, often used by captive portals.
RFC Says
"The 511 (Network Authentication Required) status code indicates that the client needs to authenticate to gain network access. The response representation SHOULD contain a link to a resource that allows the user to submit credentials."
Plain English:
511 means 'You need to log in to the network (like a WiFi captive portal) before you can access the internet.' This is commonly seen at coffee shops, hotels, and airports. It's not about authenticating with the destination server (that's 401) - it's about authenticating with the network itself.
Common Misinterpretation
Don't use 511 for application authentication - use 401 or 403. Use 511 only for captive portals and network-level authentication. Most application developers will never need to return 511 - it's returned by network infrastructure, not application servers.
Ready-to-use code for returning this HTTP status in your application:
// Express.js
app.get('/example', (req, res) => {
res.status(511).json({
error: 'Network Authentication Required',
message: 'Your error message here'
});
});
// Native HTTP
const http = require('http');
http.createServer((req, res) => {
res.writeHead(511, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
error: 'Network Authentication Required',
message: 'Your error message here'
}));
}).listen(3000);