tech:notes_curl_wget
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| tech:notes_curl_wget [2025/10/30 17:05] – Jean-Baptiste | tech:notes_curl_wget [2026/06/17 11:06] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Note curl wget | ||
| + | |||
| + | ## URL / URI | ||
| + | |||
| + | Voir : | ||
| + | * [Disséquons une URL, seconde partie](https:// | ||
| + | |||
| + | URI (Uniform Resource Identifier) : | ||
| + | * Name : URN (Uniform Resource Name) | ||
| + | * Location : URL (Uniform Resource Locator) | ||
| + | |||
| + | |||
| + | ### URI | ||
| + | |||
| + | URL, URI and URN | ||
| + | |||
| + | ### URL | ||
| + | |||
| + | En anglais, on la décrit ainsi : | ||
| + | ~~~ | ||
| + | scheme : // authority / path ? query # hash | ||
| + | ~~~ | ||
| + | |||
| + | Dans sa traduction française : | ||
| + | ~~~ | ||
| + | plan : // autorité / chemin ? requête # fragment | ||
| + | ~~~ | ||
| + | |||
| + | Enfin , comme on l' | ||
| + | ~~~ | ||
| + | comment : // chez_qui / où ? question # extrait | ||
| + | ~~~ | ||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | Syntax of URL | ||
| + | ~~~ | ||
| + | scheme: subdomain/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## wget / curl | ||
| + | |||
| + | curl as wget | ||
| + | |||
| + | ~~~bash | ||
| + | curl -O -L http:// | ||
| + | ~~~ | ||
| + | |||
| + | Point wget to TOR/ | ||
| + | |||
| + | ~~~bash | ||
| + | #export http_proxy=http:// | ||
| + | #export https_proxy=http:// | ||
| + | export ALL_PROXY=http:// | ||
| + | |||
| + | # Ou | ||
| + | |||
| + | curl -x " | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## curl | ||
| + | |||
| + | Voir aussi **HTTPie** | ||
| + | |||
| + | Voir : | ||
| + | * [Utiliser les REST API JSON avec cURL](http:// | ||
| + | |||
| + | |||
| + | JSON | ||
| + | ~~~bash | ||
| + | curl -k https:// | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | curl --globoff --request POST \ | ||
| + | --header " | ||
| + | --url " | ||
| + | |||
| + | curl --request POST \ | ||
| + | --header " | ||
| + | --header " | ||
| + | --data '{ " | ||
| + | --url " | ||
| + | ~~~ | ||
| + | Source : https:// | ||
| + | |||
| + | |||
| + | Préciser le host sans modifier les /etc/hosts | ||
| + | ~~~bash | ||
| + | curl -H " | ||
| + | ~~~ | ||
| + | |||
| + | Météo (Basé sur Wego) | ||
| + | ~~~bash | ||
| + | curl -4 wttr.in | ||
| + | curl -H " | ||
| + | ~~~ | ||
| + | |||
| + | /etc/hosts | ||
| + | ~~~bash | ||
| + | curl --resolve www.acme.fr: | ||
| + | | ||
| + | | ||
| + | ~~~ | ||
| + | |||
| + | Forcer SSLv3 | ||
| + | Pour vérifier que ça ne marche pas, car ca chiffrement est obsolète | ||
| + | `-k` Pour les certificat auto-signé | ||
| + | |||
| + | Voir `CURLOPT_SSLVERSION` | ||
| + | ~~~bash | ||
| + | curl -3 -k --show-error --verbose https:// | ||
| + | ~~~ | ||
| + | |||
| + | Erreur status code | ||
| + | ~~~bash | ||
| + | curl --show-error --verbose -I http:// | ||
| + | curl --write-out " | ||
| + | |||
| + | curl -s -o /dev/null -k -I -w " | ||
| + | ~~~ | ||
| + | |||
| + | Timeout | ||
| + | ~~~bash | ||
| + | curl -m 3 https:// | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ### Fichier config .curlrc | ||
| + | |||
| + | `.curlrc` | ||
| + | ~~~ | ||
| + | # Source : https:// | ||
| + | |||
| + | # store the trace in curl_trace.txt file. beware that multiple executions of the curl command will overwrite this file | ||
| + | --trace curl_trace.txt | ||
| + | |||
| + | # store the header info in curl_headers.txt file. beware that multiple executions of the curl command will overwrite this file | ||
| + | --dump-header curl_headers.txt | ||
| + | |||
| + | #change the below referrer URL or comment it out entirely | ||
| + | -e " | ||
| + | |||
| + | #change the below useragent string. get your/other UA strings from http:// | ||
| + | -A " | ||
| + | |||
| + | #some headers | ||
| + | -H " | ||
| + | -H " | ||
| + | -H " | ||
| + | -H " | ||
| + | ~~~ | ||
| + | |||
| + | `.curlrc` | ||
| + | ~~~ | ||
| + | Source https:// | ||
| + | |||
| + | # Limit the time (in seconds) the connection to the server is allowed to take | ||
| + | connect-timeout = 30 | ||
| + | |||
| + | # Limit the time (in seconds) the whole operation is allowed to take | ||
| + | # (prevents cURL from hanging due to slow networks or links going down) | ||
| + | max-time = 300 | ||
| + | |||
| + | # When following a redirect, automatically set the previous URL as referer | ||
| + | referer = "; | ||
| + | |||
| + | # cURL default configuration file | ||
| + | # http:// | ||
| + | |||
| + | # Show error messages | ||
| + | show-error | ||
| + | |||
| + | # Show progress using a progress meter | ||
| + | progress-bar | ||
| + | |||
| + | # Send a fake UA string for the HTTP servers that sniff it | ||
| + | user-agent = " | ||
| + | ~~~ | ||
| + | |||
| + | Upload | ||
| + | ~~~bash | ||
| + | curl -v -u admin: | ||
| + | ~~~ | ||
| + | |||
| + | HTTP POST files here | ||
| + | ~~~bash | ||
| + | curl --proxy 127.0.0.1: | ||
| + | ~~~ | ||
| + | |||
| + | Or with status bar | ||
| + | ~~~bash | ||
| + | curl --proxy 127.0.0.1: | ||
| + | ~~~ | ||
| + | |||
| + | Upload command output | ||
| + | ~~~bash | ||
| + | command | curl -T - --proxy 127.0.0.1: | ||
| + | ~~~ | ||
| + | |||
| + | Upload command output with stderr | ||
| + | ~~~bash | ||
| + | command 2>&1 | curl -T - --proxy 127.0.0.1: | ||
| + | ~~~ | ||
| + | |||
| + | Or you can shorten URLs | ||
| + | ~~~bash | ||
| + | curl --proxy 127.0.0.1: | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ## wget | ||
| + | |||
| + | Autres | ||
| + | ~~~bash | ||
| + | wget --no-cache --no-cookie | ||
| + | ~~~ | ||
| + | |||
| + | #### wget - preserve filename | ||
| + | |||
| + | ~~~bash | ||
| + | wget https:// | ||
| + | # Saving to: ' | ||
| + | |||
| + | wget --content-disposition https:// | ||
| + | # Saving to: ' | ||
| + | |||
| + | wget -O plop https:// | ||
| + | # Saving to: ‘plop' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### Autres | ||
| + | |||
| + | Fix curl client certificate error: curl: (58) unable to set private key file | ||
| + | http:// | ||
| + | |||
| + | 15 Practical Linux cURL Command Examples (cURL Download Examples) | ||
| + | http:// | ||
| + | |||
| + | |||
| + | |||
| + | Download the webpage with wget. The wget options (-E, -k, etc.) are CASE SENSITIVE! The maximum depth to which the retrieval may descend is specified with the ‘-l’ option: | ||
| + | |||
| + | ~~~bash | ||
| + | wget -E -k -p -nd -r -l 1 -np -P < | ||
| + | ~~~ | ||
| + | |||
| + | wget : Ignore robots restrictions | ||
| + | ~~~bash | ||
| + | wget -e robots=off --wait 1 http:// | ||
| + | ~~~ | ||
| + | |||
| + | Dossier répertoire directory | ||
| + | ~~~bash | ||
| + | wget http:// | ||
| + | ~~~ | ||
| + | |||
| + | A partir d'un fichier d'URL | ||
| + | ~~~bash | ||
| + | wget --no-proxy -i providers.txt -P / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ### Notes exemple Dokuwiki | ||
| + | |||
| + | wget | ||
| + | ~~~bash | ||
| + | wget --max-redirect=4 --output-document=siteexport.zip --post-data=" | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | wget -E -r http:// | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | curl | ||
| + | ~~~bash | ||
| + | curl -L --max-redirs 46 -o siteexport.zip -d " | ||
| + | ~~~ | ||
| + | |||
| + | ### Notes Curl certificat auto-signé | ||
| + | |||
| + | Pour ignoré le certificat | ||
| + | ~~~bash | ||
| + | curl -k https:// | ||
| + | wget --no-check-certificate https:// | ||
| + | ~~~ | ||
| + | |||
| + | Pour enregistrer le certificat et vérifier | ||
| + | ~~~bash | ||
| + | openssl s_client -showcerts -connect www.acme.fr: | ||
| + | # ou | ||
| + | curl -k -w %{certs} https:// | ||
| + | ~~~ | ||
| + | |||
| + | Tester | ||
| + | ~~~bash | ||
| + | curl --cacert cacert.pem | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ou avec wget | ||
| + | ~~~bash | ||
| + | wget --ca-certificate=cert.pem https:// | ||
| + | ~~~ | ||
| + | |||
| + | Voir | ||
| + | * [[Notes SSL_TLS HTTPS client OpenSSL]] | ||
| + | * [[PKI - CA - Cert - Ajouter une autorité de certification]] | ||
| + | |||
| + | |||
| + | Enlever la CA | ||
| + | ~~~bash | ||
| + | rm / | ||
| + | update-ca-certificates --fresh | ||
| + | ~~~ | ||
| + | |||
| + | TODO : equivalement pour Redhat avec `update-ca-trust` | ||
| + | |||
| + | `.curlrc` | ||
| + | ~~~bash | ||
| + | cacert=/ | ||
| + | ~~~ | ||
| + | |||
| + | Ou, à éviter mais possible | ||
| + | `.curlrc` | ||
| + | ~~~bash | ||
| + | insecure | ||
| + | ~~~ | ||
| + | |||
| + | https sous java | ||
| + | Voir la paquet **ca-certificates-java** | ||
| + | |||
| + | ~~~bash | ||
| + | openssl s_client -showcerts -connect 192.168.4.13: | ||
| + | |||
| + | # test | ||
| + | curl --show-error --verbose --cacert cert.crt https:// | ||
| + | |||
| + | cp cert.crt / | ||
| + | update-ca-certificates | ||
| + | |||
| + | / | ||
| + | systemctl restart jenkins | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Python | ||
| + | |||
| + | ~~~python | ||
| + | import requests | ||
| + | |||
| + | # No warn for bad https ' | ||
| + | requests.packages.urllib3.disable_warnings() | ||
| + | |||
| + | # HTTP GET all users ids | ||
| + | r = requests.get(' | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Exemple HTTPS certificat client | ||
| + | |||
| + | ~~~bash | ||
| + | curl --verbose --show-error --tlsv1.2 --cert / | ||
| + | wget --debug --verbose --no-check-certificate --secure-protocol=TLSv1_2 --certificate=/ | ||
| + | (echo -ne "GET /plop HTTP/ | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | curl --cacert keys/ca.crt --key keys/ | ||
| + | wget --ca-certificate=keys/ | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Envoyer un fichier en ligne de commande (upload web) | ||
| + | |||
| + | |||
| + | [Goploader](https:// | ||
| + | |||
| + | ~~~bash | ||
| + | # Your file will be named myfile.txt | ||
| + | curl -F file=@myfile.txt https:// | ||
| + | |||
| + | # Your file will be named myamazingfile! | ||
| + | curl -F name=" | ||
| + | |||
| + | # Reads data from stdin | ||
| + | cat myfile.txt | curl -F name=" | ||
| + | ~~~ | ||
| + | |||
| + | ## Sécurité | ||
| + | |||
| + | Pipe bash | ||
| + | |||
| + | https:// | ||
| + | |||
| + | ~~~bash | ||
| + | curl -sSk http:// | ||
| + | curl -sSk http:// | ||
| + | ~~~ | ||
| + | |||
