Codes de statut HTTP

Tous les codes de statut HTTP enregistrés : ce qu’ils signifient, quand on les rencontre et où ils sont définis.

100ContinueThe server received the request headers and the client should send the body.
101Switching ProtocolsThe server is switching to the protocol the client asked for in the Upgrade header.
102ProcessingThe server accepted the request and is still working on it.
103Early HintsHeaders sent ahead of the final response so the client can start preloading resources.
104Upload Resumption SupportedThe server supports resuming this upload if it is interrupted.
200OKThe request succeeded.
201CreatedThe request succeeded and created a new resource.
202AcceptedThe request was accepted for processing, which hasn't finished.
203Non-Authoritative InformationSuccess, but a proxy changed the response the origin server sent.
204No ContentThe request succeeded and there is no body.
205Reset ContentSuccess; the client should reset the form or view that sent the request.
206Partial ContentThe response holds only the byte range the client asked for.
207Multi-StatusThe body holds separate status codes for several operations.
208Already ReportedMembers of this collection were already listed earlier in the same 207 response.
226IM UsedThe response is a delta applied to the current instance, not the full resource.
300Multiple ChoicesThe resource has several representations and the client should choose one.
301Moved PermanentlyThe resource has a new permanent URL, given in the Location header.
302FoundThe resource is temporarily at the URL in the Location header.
303See OtherThe result is at another URL, which the client should fetch with GET.
304Not ModifiedThe cached copy is still valid, so no body is sent.
305Use ProxyThe resource must be accessed through the proxy in the Location header.
306(Unused)Reserved; it was once used for Switch Proxy and is no longer used.
307Temporary RedirectThe resource is temporarily at another URL; repeat the request there with the same method and body.
308Permanent RedirectThe resource has moved permanently; repeat the request at the new URL with the same method and body.
400Bad RequestThe server can't process the request because it is malformed.
401UnauthorizedThe request has no valid credentials for this resource.
402Payment RequiredReserved for future use.
403ForbiddenThe server understood the request but refuses to allow it.
404Not FoundThe server has nothing at this URL.
405Method Not AllowedThe resource exists but doesn't support this HTTP method.
406Not AcceptableThe server can't produce a response in any format the Accept headers allow.
407Proxy Authentication RequiredThe client must authenticate with the proxy first.
408Request TimeoutThe server gave up waiting for the client to finish sending the request.
409ConflictThe request conflicts with the current state of the resource.
410GoneThe resource existed but has been removed permanently.
411Length RequiredThe server needs a Content-Length header.
412Precondition FailedA condition in the request headers, such as If-Match, is false.
413Content Too LargeThe request body is larger than the server accepts.
414URI Too LongThe URL is longer than the server accepts.
415Unsupported Media TypeThe server doesn't accept the body's format.
416Range Not SatisfiableThe requested byte range is outside the resource.
417Expectation FailedThe server can't meet the Expect header.
418I'm a teapotA joke code from RFC 2324, kept reserved as "(Unused)" because so much software already recognizes it.
421Misdirected RequestThe request reached a server that can't answer for this host.
422Unprocessable ContentThe request is well formed but its content fails validation.
423LockedThe resource is locked.
424Failed DependencyThe request failed because a request it depended on failed.
425Too EarlyThe server won't process a request that might be replayed.
426Upgrade RequiredThe client must switch to another protocol, named in the Upgrade header.
428Precondition RequiredThe server requires a conditional request, such as one with If-Match.
429Too Many RequestsThe client has sent too many requests in a given time and is being rate limited.
431Request Header Fields Too LargeThe headers, or one header, are too large.
451Unavailable For Legal ReasonsThe resource can't be served for legal reasons.
500Internal Server ErrorThe server hit an unexpected condition.
501Not ImplementedThe server doesn't support the functionality needed, such as the request method.
502Bad GatewayA gateway or proxy got an invalid response from the server behind it.
503Service UnavailableThe server can't handle the request right now.
504Gateway TimeoutA gateway or proxy didn't get a response from the server behind it in time.
505HTTP Version Not SupportedThe server doesn't support the HTTP version of the request.
506Variant Also NegotiatesContent negotiation is misconfigured on the server.
507Insufficient StorageThe server can't store what it needs to complete the request.
508Loop DetectedThe server found an infinite loop while processing the request.
510Not ExtendedThe request needs an HTTP extension the server requires.
511Network Authentication RequiredThe client must authenticate to get network access.
419Page ExpiredLaravelThe CSRF token is missing or expired.
420Enhance Your CalmTwitter (historical)The client is being rate limited.
444No Responsenginxnginx closed the connection without sending a response.
494Request Header Too Largenginxnginx's code for headers over its buffer limits.
495SSL Certificate ErrornginxThe client certificate failed verification.
496SSL Certificate RequirednginxA required client certificate wasn't sent.
497HTTP Request Sent to HTTPS PortnginxA plain HTTP request reached a port that expects TLS.
499Client Closed RequestnginxThe client closed the connection before nginx sent the response.
509Bandwidth Limit ExceededApache / cPanelThe site has used up its bandwidth allowance.
520Web Server Returned an Unknown ErrorCloudflareThe origin server returned something Cloudflare couldn't use.
521Web Server Is DownCloudflareThe origin server refused Cloudflare's connection.
522Connection Timed OutCloudflareCloudflare couldn't establish a TCP connection to the origin in time.
523Origin Is UnreachableCloudflareCloudflare can't reach the origin server.
524A Timeout OccurredCloudflareCloudflare connected to the origin, but it didn't respond in time.
525SSL Handshake FailedCloudflareThe TLS handshake between Cloudflare and the origin failed.
526Invalid SSL CertificateCloudflareCloudflare couldn't validate the origin's certificate.
530Origin DNS ErrorCloudflareCloudflare returns 530 together with a 1xxx error, most often 1016 (origin DNS error).

Select a code

Pick a code from the list to see when it is used, the specification that defines it and a command to try it. Use the arrow keys to move through the list.
64 registered codes · 17 unofficial

Qu’est-ce qu’un code de statut HTTP ?

Chaque réponse HTTP commence par un code de statut à trois chiffres qui indique ce qui est arrivé à la requête. Le premier chiffre donne la classe : 1xx est informatif, 2xx signifie succès, 3xx redirection, 4xx que la requête était incorrecte et 5xx que le serveur a échoué.

Les codes sont définis dans la RFC 9110, HTTP Semantics, qui a remplacé la RFC 7231 en 2022, et dans quelques autres RFC comme la RFC 6585 pour 429 Too Many Requests. L’IANA tient le registre officiel. La RFC 9110 a renommé deux codes : 413 s’appelle désormais Content Too Large (anciennement Payload Too Large) et 422 Unprocessable Content (anciennement Unprocessable Entity). Les numéros et leur comportement n’ont pas changé.

Certains codes que vous croiserez ne figurent pas dans le registre. nginx journalise 499 quand un client ferme la connexion avant que la réponse soit prête, Cloudflare renvoie de 520 à 526 quand il n’obtient pas de réponse exploitable du serveur d’origine, et Laravel renvoie 419 quand le jeton CSRF d’un formulaire a expiré. Ils sont listés à part, marqués comme non officiels.

Le code de statut est la première chose qu’un test d’API doit vérifier, car le reste de la réponse en dépend. Un 201 Created indique qu’un POST a créé une nouvelle ressource, un 404 que la ressource n’existe pas et un 500 que le serveur a échoué ; dans ce cas, le corps peut être une page d’erreur au lieu du JSON attendu.

Comment utiliser cet outil

  1. 1Parcourez la liste, groupée de 1xx à 5xx avec les codes non officiels à la fin, ou filtrez-la avec les boutons de classe.
  2. 2Recherchez par numéro, nom ou symptôme, comme 404, 5xx, redirect, timeout ou un ancien nom comme Unprocessable Entity. Appuyez sur / pour aller au champ de recherche depuis n’importe où sur la page.
  3. 3Sélectionnez un code, ou parcourez la liste avec les flèches du clavier, pour voir ce qu’il signifie, quand on le rencontre, la spécification qui le définit et les codes voisins à comparer.
  4. 4Copiez la commande curl sous Try it pour que l’endpoint de statut de testingapis.com renvoie ce code, ou copiez un lien : /fr/tools/http-status/#429 ouvre directement le 429.

Dépannage

Un 401 alors que vous avez envoyé un jeton
Le jeton est expiré, mal formé, envoyé dans le mauvais en-tête ou il lui manque le préfixe Bearer . L’en-tête de réponse WWW-Authenticate indique souvent lequel. Un 403, en revanche, signifie que le jeton est valide mais n’a pas la permission.
Un 415 pour un corps JSON
La requête n’a pas d’en-tête Content-Type: application/json, donc le serveur ne traite pas le corps comme du JSON. Le -d de curl envoie application/x-www-form-urlencoded sauf si vous définissez l’en-tête.
Un POST devient un GET après une redirection
Les clients suivent les 301 et 302 en répétant la requête en GET, sans corps. Les serveurs qui doivent conserver la méthode doivent envoyer 307 ou 308.
Un 502 ou un 504 venant d’un répartiteur de charge
Le proxy placé devant l’application n’a pas reçu de réponse valide : 502 quand l’application a planté ou fermé la connexion, 504 quand elle a dépassé le délai du proxy. Les logs de l’application elle-même montrent la cause.
499 dans les logs nginx
Le client a abandonné avant que la réponse soit prête : un utilisateur a quitté la page, ou un client ou un proxy en amont a atteint son délai. La cause habituelle est un backend lent.

Questions fréquentes

Quelle est la différence entre 401 et 403 ?

401 Unauthorized signifie que le serveur ne sait pas qui vous êtes : les identifiants sont absents, expirés ou erronés. 403 Forbidden signifie qu’il sait qui vous êtes, mais que cette identité n’a pas le droit de faire cela. Se reconnecter peut régler un 401, pas un 403.

Une API doit-elle renvoyer 400 ou 422 pour une entrée invalide ?

Les deux sont utilisés. Une convention courante est 400 pour une requête que le serveur ne peut pas lire du tout, comme un JSON mal formé, et 422 pour des données bien formées qui enfreignent une règle, comme un champ obligatoire manquant ou un e-mail invalide.

Quelle est la différence entre 502, 503 et 504 ?

Les trois viennent généralement d’un proxy ou d’un répartiteur de charge placé devant l’application. 502 Bad Gateway signifie qu’il a reçu une réponse invalide du serveur derrière lui, 503 Service Unavailable que le service est surchargé ou en maintenance, et 504 Gateway Timeout que le serveur derrière lui n’a pas répondu à temps.

Quel code de redirection utiliser ?

301 et 308 sont permanents, 302 et 307 temporaires. 307 et 308 imposent au client de répéter la requête avec la même méthode et le même corps, alors que les clients transforment généralement un POST en GET après un 301 ou un 302. Utilisez 303 See Other pour envoyer un client vers une page de résultat après un POST.

418 I'm a teapot est-il un vrai code de statut ?

Il vient de la RFC 2324, un poisson d’avril de 1998 sur le contrôle des cafetières. La RFC 9110 liste le 418 comme inutilisé mais réservé, parce que beaucoup de logiciels le reconnaissent déjà. Il n’est pas fait pour de vraies erreurs.

Comment tester la façon dont mon application gère un code de statut précis ?

Appelez un endpoint qui renvoie le code demandé. GET https://api.testingapis.com/api/status/503 répond avec un 503 et les en-têtes que ce statut porte habituellement, comme Retry-After. N’importe quel code de 200 à 599 fonctionne.