-
-
Save claudiojcas/b9b45b5054702b7e339b488ac4e8b581 to your computer and use it in GitHub Desktop.
Revisions
-
claudiojcas revised this gist
Oct 28, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # Sobre o comando `curl` ## Parametros mais comuns Parametro |Descrição -
claudiojcas revised this gist
Oct 27, 2019 . 3 changed files with 46 additions and 82 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,110 +1,74 @@ # Sobre o camando `curl` ## Parametros mais comuns Parametro |Descrição -----------------------------|--------- -#, --progress-bar |Faz com que a exibição seja uma barra de progresso simples em vez do medidor padrão mais informativo. -b, --cookie <name=data> |Forneça o cookie com solicitação. Se `=`, especifica o arquivo de cookie a ser usado (consulte `-c`). -c, --cookie-jar <file name> |Arquivo para salvar os cookies de resposta. -d, --data <data> |Envie dados especificados na solicitação `POST`. (Detalhes fornecidos abaixo.) -f, --fail |Falha silenciosamente (não produza o formulário de erro HTML se retornado). -F, --form <name=content> |Envie dados do como campos de formulário. -H, --header <header> |Cabeçalhos a serem fornecidos com a solicitação. -i, --include |Inclua cabeçalhos HTTP na saída. -I, --head |Buscar apenas cabeçalhos. -k, --insecure |Permita que conexões inseguras sejam bem-sucedidas. -L, --location |Siga redirecionamentos. -o, --output <file> |Grava a saída em <file>. Pode usar `--create-dirs` em conjunto com isso para criar qualquer diretório especificado no caminho `-o`. -O, --remote-name |Grave a saída no arquivo nomeado como o arquivo remoto (apenas grava no diretório atual). -s, --silent |Modo silencioso. Use com `-S` para forçá-lo a mostrar erros. -v, --verbose |Forneça mais informações (úteis para depuração). -w, --write-out <format> |Faça as informações de exibição de `curl` no stdout após uma transferência concluída. Consulte a página do manual para obter mais detalhes sobre variáveis disponíveis. Maneira conveniente de forçar o `curl` a acrescentar uma nova linha à saída: `-w"\n"` (pode adicionar para `~/.curlrc`). -X <método>, --request |O método de solicitação a ser usado. ### POST Ao enviar dados por uma solicitação `POST` ou `PUT`, dois formatos comuns (especificados no cabeçalho `Content-Type`) são: * `application/json` * `application/x-www-form-urlencoded` Muitas APIs aceitarão os dois formatos; portanto, se você estiver usando `curl` na linha de comando, pode ser um pouco mais fácil usar o formato codificado por url em vez do json, porque * o formato json requer várias citações extras * `curl` envia o formulário url codificado por padrão, portanto, para json, o cabeçalho `Content-Type` deve ser explicitamente definido Esta lista fornece exemplos para usar os dois formatos, incluindo como usar arquivos de dados de amostra em qualquer formato com suas solicitações `curl`. ## Usando `curl` Para enviar dados com solicitações **POST** e **PUT**, estas são opções comuns `curl`: * Tipos de **request** * `-X POST` * `-X PUT` * Tipos de **content header** * `-H "Content-Type: application/x-www-form-urlencoded"` * `-H "Content-Type: application/json"` * Formas de **data** * forma de urlencoded: `-d "param1=value1¶m2=value2"` ou `-d @data.txt` * forma de json: `-d '{"key1":"value1", "key2":"value2"}'` ou `-d @data.json` ### Exemplos #### POST form-url via `application/x-www-form-urlencoded` `application/x-www-form-urlencoded` é o padrão: curl -d "param1=value1¶m2=value2" -X POST http://localhost:3000/data explicitando: curl -d "param1=value1¶m2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data com arquivo de dados: curl -d "@data.txt" -X POST http://localhost:3000/data #### POST json via `application/json` curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data com arquivo de dados curl -d "@data.json" -X POST http://localhost:3000/data This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ field1=value1&field2=value2 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,8 @@ var app = require('express')(); var bodyParser = require('body-parser'); app.use(bodyParser.json()); // para analisar 'application/json' app.use(bodyParser.urlencoded({ extended: true })); // para analisar 'application/x-www-form-urlencoded' app.post('/data', function (req, res) { console.log(req.body); -
subfuzion revised this gist
Jun 12, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ `-b, --cookie <name=data>` Supply cookie with request. If no `=`, then specifies the cookie file to use (see `-c`). `-c, --cookie-jar <file name>` File to save response cookies to. `-d, --data <data>` -
subfuzion revised this gist
Jun 12, 2016 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -43,8 +43,13 @@ `-s, --silent` Silent (quiet) mode. Use with `-S` to force it to show errors. `-v, --verbose` Provide more information (useful for debugging). `-w, --write-out <format>` Make curl display information on stdout after a completed transfer. See man page for more details on available variables. Convenient way to force curl to append a newline to output: `-w "\n"` (can add to `~/.curlrc`). `-X, --request` The request method to use. -
subfuzion revised this gist
Jun 12, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ `-f, --fail` Fail silently (don't output HTML error form if returned). `-F, --form <name=content>` Submit form data. `-H, --header <header>` -
subfuzion revised this gist
Jun 12, 2016 . 1 changed file with 54 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,57 @@ ## Common Options `-#, --progress-bar` Make curl display a simple progress bar instead of the more informational standard meter. `-b, --cookie <name=data>` Supply cookie with request. If no `=`, then specifies the cookie file to use (see `-c`). `-c, --cokkie-jar <file name>` File to save response cookies to. `-d, --data <data>` Send specified data in POST request. Details provided below. `-f, --fail` Fail silently (don't output HTML error form if returned). `-F, --form <name=content> Submit form data. `-H, --header <header>` Headers to supply with request. `-i, --include` Include HTTP headers in the output. `-I, --head` Fetch headers only. `-k, --insecure` Allow insecure connections to succeed. `-L, --location` Follow redirects. `-o, --output <file>` Write output to <file>. Can use `--create-dirs` in conjunction with this to create any directories specified in the `-o` path. `-O, --remote-name` Write output to file named like the remote file (only writes to current directory). `-s, --silent` Silent (quiet) mode. Use with `-S` to force it to show errors. `-v, verbose` Provide more information (useful for debugging). `-X, --request` The request method to use. ## POST When sending data via a POST or PUT request, two common formats (specified via the `Content-Type` header) are: * `application/json` * `application/x-www-form-urlencoded` -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ For sending data with POST and PUT requests, these are common `curl` options: ## Examples ### POST application/x-www-form-urlencoded `application/x-www-form-urlencoded` is the default: @@ -40,7 +40,7 @@ with a data file curl -d "@data.txt" -X POST http://localhost:3000/data ### POST application/json curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Many APIs will accept both formats, so if you're using `curl` at the command lin This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests. ## curl usage For sending data with POST and PUT requests, these are common `curl` options: @@ -23,6 +23,8 @@ For sending data with POST and PUT requests, these are common `curl` options: * data * form urlencoded: `-d "param1=value1¶m2=value2"` or `-d @data.txt` * json: `-d '{"key1":"value1", "key2":"value2"}'` or `-d @data.json` ## Examples ##### POST application/x-www-form-urlencoded -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 18 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,28 @@ When sending data via a POST or PUT request, two common formats (specified via t * `application/json` * `application/x-www-form-urlencoded` Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the form urlencoded format instead of json because * the json format requires a bunch of extra quoting * curl will send form urlencoded by default, so for json the `Content-Type` header must be explicitly set This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests. ### curl usage For sending data with POST and PUT requests, these are common `curl` options: * request type * `-X POST` * `-X PUT` * content type header * `-H "Content-Type: application/x-www-form-urlencoded"` * `-H "Content-Type: application/json"` * data * form urlencoded: `-d "param1=value1¶m2=value2"` or `-d @data.txt` * json: `-d '{"key1":"value1", "key2":"value2"}'` or `-d @data.json` ##### POST application/x-www-form-urlencoded `application/x-www-form-urlencoded` is the default: -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Many APIs will accept both formats, so if you're using `curl` at the command lin * the json format requires a bunch of extra quoting * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set This gist provides examples for using both formats, including how to use sample data files in either format with your `curl` requests. ##### POST application/x-www-form-urlencoded -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ When sending data via a POST or PUT request, two common formats (specified via t * `application/json` * `application/x-www-form-urlencoded` Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format instead of json because * the json format requires a bunch of extra quoting * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set -
subfuzion revised this gist
May 13, 2016 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,12 @@ When sending data via a POST or PUT request, two common formats (specified via the `Content-Type` header) are: * `application/json` * `application/x-www-form-urlencoded` Many APIs will accept both formats, so if you're using `curl` at the command line, it can be a bit easier to use the urlencoded format than json because * the json format requires a bunch of extra quoting * curl will send urlencoded by default, so for json the `Content-Type` header must be explicitly set ##### POST application/x-www-form-urlencoded `application/x-www-form-urlencoded` is the default: -
tonypujals revised this gist
Feb 26, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ##### POST application/x-www-form-urlencoded `application/x-www-form-urlencoded` is the default: @@ -12,7 +12,7 @@ with a data file curl -d "@data.txt" -X POST http://localhost:3000/data ##### POST application/json curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data -
tonypujals created this gist
Feb 26, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ ## POST application/x-www-form-urlencoded `application/x-www-form-urlencoded` is the default: curl -d "param1=value1¶m2=value2" -X POST http://localhost:3000/data explicit: curl -d "param1=value1¶m2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data with a data file curl -d "@data.txt" -X POST http://localhost:3000/data ## POST application/json curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data with a data file curl -d "@data.json" -X POST http://localhost:3000/data This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ { "key1":"value1", "key2":"value2" } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ param1=value1¶m2=value2 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ { "name": "postdemo", "version": "1.0.0", "scripts": { "start": "node server.js" }, "dependencies": { "body-parser": "^1.15.0", "express": "^4.13.4" } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ var app = require('express')(); var bodyParser = require('body-parser'); app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.post('/data', function (req, res) { console.log(req.body); res.end(); }); app.listen(3000);