HTTP 401 and 407 — Which Credentials Failed?
Published
Read the authentication challenge
A 401 Unauthorized response asks the client to authenticate to access the requested resource. Look for WWW-Authenticate to see which scheme the server offers. The credentials or token for that resource go to the server. A 407 Proxy Authentication Required asks the client to authenticate to the proxy. Its challenge goes in Proxy-Authenticate. Configure the proxy credentials in the client’s proxy settings. HTTP authentication in RFC 9110.
Compare two results for the same HTTPS URL
With an HTTP proxy, cURL sends CONNECT to the gateway before it can request an HTTPS resource. Use an approved proxy and a test URL you control. The example prints the response headers and a short status summary. It sends a GET request and leaves redirects unfollowed. On Windows, run curl.exe and replace /dev/null with NUL.
curl --disable --noproxy "localhost" --proxy "http://gateway.example:8080" --silent --show-error --max-time 15 --dump-header - --output /dev/null --write-out "CONNECT %{http_connect} | Target %{http_code}\n" "https://app.example/account"
The proxy asks for authentication
HTTP/1.1 407 Proxy Authentication Required
Proxy-Authenticate: Basic realm="Example proxy"
CONNECT 407 | Target 000
The HTTPS request to /account did not receive an HTTP response. Check whether the endpoint expects proxy credentials or an approved source IP. The example uses Basic, and the actual challenge can advertise a different scheme. A client with valid credentials can answer a challenge and then complete CONNECT in a later step. Check the final outcome before treating the first challenge as a failure. Compare proxy authentication methods.
The proxy accepts CONNECT and the destination asks for authentication
HTTP/1.1 200 Connection established
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="Example site"
CONNECT 200 | Target 401
The tunnel opened. The destination side then asked for authentication to /account. For an API, check the required scheme, token scope and target URL. For a browser app, check the affected profile and session. A browser can reach a page using a cached login that a fresh terminal command lacks. Read CONNECT and target statuses in cURL.
Choose what to verify in the online tester
Start with the default IP check to confirm the proxy route. Then compare a permitted request to the same destination. A 407 during the proxy connection and a 401 from a protected website call for different fixes. Where the destination requires application credentials, verify that login separately using the application’s normal client. For support, record which step issued the challenge and which scheme it requested. Omit Authorization, Proxy-Authorization and cookie values from any shared trace. Read the tester’s result fields.