Accueil·Commandes du terminal

curl

Réseau

Syntaxe

curl [options] <url>

Recupere une URL et affiche le corps dans le terminal ; contrairement a un navigateur, il ne suit pas les redirections sans `-L`, si bien qu'un 301 ressemble a une reponse vide.

Options courantes

OptionSignification
-LFollow redirects. curl does not follow them on its own, unlike a browser.
-iPrint the response headers along with the body; -I sends HEAD and prints headers only.
-d '{"a":1}'Send a request body. This alone already means POST.
-H "Content-Type: application/json"Add a request header; repeat -H for more.
-X PUTOverride the method. Unnecessary with -d, which is already a POST.
-o <file> / -OSave the body to a file / save it under the remote filename.
-s / -sSNo progress meter / silent but still print errors.
-fExit nonzero on HTTP 4xx and 5xx instead of printing the error page.
-kSkip certificate verification. Debugging only, never in production.

Exemples

curl -fsSL https://example.com/install.sh -o install.sh

Download quietly, follow redirects, fail loudly on a 404.

curl -i -H "Content-Type: application/json" -d '{"name":"a"}' https://api.example.com/items

POST JSON and read the response headers.

curl -s -o /dev/null -w "%{http_code}\n" https://example.com

Print just the status code.

Quand une connexion échoue, ceux-ci délimitent jusqu’où elle est allée : le nom ne se résout pas, pas de route, ou le port est fermé.

Comment lire

  • Les crochets [ ] marquent une partie facultative.
  • Les points de suspension … signifient qu’on peut en mettre plusieurs.
  • Les options sont sensibles à la casse : sur certaines commandes, -r et -R ne font pas la même chose.

Questions fréquentes

Q. Que fait curl ?

Recupere une URL et affiche le corps dans le terminal ; contrairement a un navigateur, il ne suit pas les redirections sans `-L`, si bien qu'un 301 ressemble a une reponse vide.

Q. Comment l’écrire ?

curl [options] <url> — les crochets marquent ce qui est facultatif.

Q. Combien d’options valent la peine ?

Il y en a 9 ici ; la liste complète est dans man curl. Cette commande relève de Réseau.

Commandes liées

page man: man curl