The 511 Network Authentication Required HTTP status code indicates that the client must authenticate itself to gain network access before the request can be fulfilled. This response is typically sent by intercepting proxies or captive portals rather than the origin server.
A 511 response means the network requires authentication, such as accepting terms or logging in. It is different from 401 Unauthorized, which is handled by the origin server. The network intercepts the request before it reaches the server.
// Example of an HTTP response with status code 511
HTTP/1.1 511 Network Authentication Required
Content-Type: text/html
Content-Length: 214
<html>
<body>
<h1>Network Authentication Required</h1>
<p>Please log in to access the internet.</p>
</body>
</html>
// Node.js Express example sending a 511 response
app.use((req,res)=>{
res.status(511).send("Network authentication required");
});
When a client receives a 511 response, the browser usually displays a login or agreement page provided by the network. Once authenticated, the original request is retried automatically or manually.
The following interactive simulation mimics a captive portal flow using JavaScript.
// Simulated captive portal authentication flow
const isAuthenticated=false;
function requestInternet(){
if(!isAuthenticated){
return "511 Network Authentication Required";
}
return "200 OK";
}
requestInternet();
Initial request returns 511. After authentication, subsequent requests succeed.