2011-06-01 09:10:14 +0000 2011-06-01 09:10:14 +0000
149
149
Advertisement

Comment afficher les données POST avec cURL ?

Advertisement

Par exemple, l'envoi vers un serveur web avec l'argument -v :

curl -v http://testserver.com/post -d "firstname=john&lastname=doe"

Et la sortie

> POST /post HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: testserver.com
> Accept: */*
> Content-Length: 28
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
(etc)

Il n'y a aucune mention des données que j'ai postées.

Y a-t-il une option dans cURL pour afficher la chaîne “firstname=john&lastname=doe” dans la sortie ?

Note : Il est évident que la chaîne que je veux se trouve dans la commande que j'ai exécutée, mais il y a plusieurs autres options d'affichage telles que –form et –data-ascii etc. J'aimerais voir les données brutes envoyées au serveur.

Advertisement
Advertisement

Réponses (4)

184
184
184
2011-06-01 10:50:42 +0000

Le plus proche que j'ai obtenu sans utiliser tcpdump est en utilisant l'option --trace-ascii :

~ curl http://w3.org/ -d "hello=there" --trace-ascii /dev/stdout
== Info: About to connect() to w3.org port 80 (#0)
== Info: Trying 128.30.52.45... == Info: connected
== Info: Connected to w3.org (128.30.52.45) port 80 (#0)
=> Send header, 210 bytes (0xd2)
0000: POST / HTTP/1.1
0011: User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
0051: 9.7 OpenSSL/0.9.8l zlib/1.2.3
0070: Host: w3.org
007e: Accept: */*
008b: Content-Length: 11
009f: Content-Type: application/x-www-form-urlencoded
00d0: 
=> Send data, 11 bytes (0xb)
0000: hello=there

Malheureusement, cela ne fonctionne pas lorsque vous affichez multipart/form-data :

~ curl http://w3.org/ -F hello=there -F testing=123 --trace-ascii /dev/stdout
== Info: About to connect() to w3.org port 80 (#0)
== Info: Trying 128.30.52.45... == Info: connected
== Info: Connected to w3.org (128.30.52.45) port 80 (#0)
=> Send header, 270 bytes (0x10e)
0000: POST / HTTP/1.1
0011: User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.1
0051: 9.7 OpenSSL/0.9.8l zlib/1.2.3
0070: Host: w3.org
007e: Accept: */*
008b: Content-Length: 244
00a0: Expect: 100-continue
00b6: Content-Type: multipart/form-data; boundary=--------------------
00f6: --------19319e4d1b79
010c: 
<= Recv header, 32 bytes (0x20)
0000: HTTP/1.1 301 Moved Permanently
36
36
36
2016-09-30 09:21:56 +0000

Ou vous pouvez tester avec https://httpbin.org/

$ curl https://httpbin.org/post -d "firstname=john&lastname=doe"
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "firstname": "john", 
    "lastname": "doe"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "27", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.43.0"
  }, 
  "json": null, 
  "origin": "*.*.*.*", 
  "url": "https://httpbin.org/post"
}
15
Advertisement
15
15
2017-05-21 13:04:14 +0000
Advertisement

Souhaite ajouter l'alternative netcat

#!/bin/bash
nc -l 8080 &

curl "http://localhost:8080" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
--data @<(cat <<EOF
{
  "me": "$USER",
  "something": $(date +%s)
}
EOF
)
9
9
9
2014-08-28 13:51:51 +0000

Vous pourriez utiliser Charles et curl --proxy localhost:8888. Simples !

Advertisement

Questions connexes

7
16
19
8
6
Advertisement
Advertisement