First decide: visiting a site or maintaining an API?
As a visitor: open the site’s normal sign-in page and sign in again. If the error persists, report the page address, time and any request ID to the site owner; omit private query values. Never send your password or session cookie with the report.
As a developer: reproduce the failing method and URL in your own environment. A successful homepage request says nothing about a protected API route.
Check a 401 in this order
- Read the challenge. RFC 9110 requires a
WWW-Authenticateresponse header with a 401. Its scheme helps identify the expected authentication. If absent, inspect the application or gateway generating the response. - Check the actual request. In your browser’s Network panel or local client, verify that the intended cookie or
Authorizationheader is present. Keep credentials out of shared screenshots and public diagnostic tools. - Match the credential to the service. Check expiry, revocation and environment: a staging token may not be accepted by production. Use the service’s documented renewal process.
- Trace the rejection. Correlate the request time or ID with authentication logs. Check whether a proxy forwards the expected credentials. Correct the failing configuration, then retry the same route.
Inspect the original response with curl
Replace the example URL with a read-only resource you administer. This unauthenticated GET prints headers and discards the body:
curl -sS -D - -o /dev/null --max-time 15 https://example.com/protected-resource
No -L is used, so a redirect cannot silently replace the initial response. -I would send HEAD instead of GET. This example does not reproduce authenticated or POST requests; use your own client for those. Response headers can contain cookies, so redact them before sharing.
401 versus 403
403 Forbidden means the server understood the request but refuses it. Renewing a token alone may not fix an access-policy rejection. Do not remove authentication to make a private endpoint return 200.
Public pages and Google Search
Google does not index content served with 401. Keep private pages protected; investigate accidental authentication on pages intended for public search. Do not use 401 to slow crawlers. Google’s HTTP guidance.
Reference: RFC 9110, 401 semantics. Related: diagnosing a 500 server error and the HTTP status directory.