curl
Rede
Uso
curl [options] <url>Baixa uma URL e imprime o corpo no terminal; ao contrario de um navegador, nao segue redirecionamentos sem `-L`, entao um 301 parece uma resposta vazia.
Opções comuns
| Opção | Significado |
|---|---|
| -L | Follow redirects. curl does not follow them on its own, unlike a browser. |
| -i | Print 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 PUT | Override the method. Unnecessary with -d, which is already a POST. |
| -o <file> / -O | Save the body to a file / save it under the remote filename. |
| -s / -sS | No progress meter / silent but still print errors. |
| -f | Exit nonzero on HTTP 4xx and 5xx instead of printing the error page. |
| -k | Skip certificate verification. Debugging only, never in production. |
Exemplos
curl -fsSL https://example.com/install.sh -o install.shDownload quietly, follow redirects, fail loudly on a 404.
curl -i -H "Content-Type: application/json" -d '{"name":"a"}' https://api.example.com/itemsPOST JSON and read the response headers.
curl -s -o /dev/null -w "%{http_code}\n" https://example.comPrint just the status code.
Quando a conexão falha, estes mostram até onde ela chegou: o nome não resolve, não há rota ou a porta está fechada.
Como ler
- Os colchetes [ ] marcam uma parte que você pode omitir.
- As reticências … indicam que você pode listar vários.
- As opções diferenciam maiúsculas: em alguns comandos -r e -R fazem coisas diferentes.
Perguntas
Q. O que curl faz?
Baixa uma URL e imprime o corpo no terminal; ao contrario de um navegador, nao segue redirecionamentos sem `-L`, entao um 301 parece uma resposta vazia.
Q. Como se digita?
curl [options] <url> — os colchetes marcam o que você pode omitir.
Q. Quantas opções vale a pena saber?
Aqui estão 9; a lista completa está em man curl. Este comando fica em Rede.
Comandos relacionados
página man: man curl