Hey,
Tout d'abord, httpie est un magnifique logiciel. Je ne me souviens plus du nombre de collègues que j'ai recommandé de l'utiliser.
Il y a un problème que j'ai rencontré. Selon la spécification, la fourniture des paramètres JSON se fait via l'opérateur :=
. Mais en lançant httpie 0.9.9 avec ces paramètres :
http post localhost/example/ param1="a b c" param2=d jparam:='["test string"]'
Entraîne un message concernant un JSON non valide. Mais ["test string"]
est un JSON valide à ma connaissance.
http: error: "jparam:='[test string]'": Expecting value: line 1 column 1 (char 0)
Peut-être que quelqu'un pourrait expliquer ce qui ne va pas ?
Corrigez-moi si je me trompe, mais un objet JSON n'est-il généralement pas au format {"key":"value"} ?
@poskadesign la commande semble correcte et cela fonctionne pour moi dans Bash. Cela pourrait être un problème d'échappement si vous utilisez un autre shell.
$ http -v httpbin.org/post param1="a b c" param2=d jparam:='["test string"]'
POST /post HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 61
Content-Type: application/json
Host: httpbin.org
User-Agent: HTTPie/0.9.9
{
"jparam": [
"test string"
],
"param1": "a b c",
"param2": "d"
}
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 568
Content-Type: application/json
Date: Sun, 14 May 2017 10:58:53 GMT
Server: meinheld/0.6.1
Via: 1.1 vegur
X-Powered-By: Flask
X-Processed-Time: 0.000903844833374
{
"args": {},
"data": "{\"param1\": \"a b c\", \"param2\": \"d\", \"jparam\": [\"test string\"]}",
"files": {},
"form": {},
"headers": {
"Accept": "application/json, */*",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Content-Length": "61",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "HTTPie/0.9.9"
},
"json": {
"jparam": [
"test string"
],
"param1": "a b c",
"param2": "d"
},
"origin": "…",
"url": "http://httpbin.org/post"
}
Bonjour, je suis novice dans les projets open source. J'aimerais travailler sur ce problème. Pourriez-vous s'il vous plaît me fournir plus d'informations?
@poskadesign De quel système d'exploitation et de quel shell s'agit-il ? Il semble que votre shell ait utilisé les guillemets doubles pour éviter le fractionnement des mots sur l'espace, mais a ensuite laissé les guillemets simples dans l'argument.
C'est quelque chose comme ça.. http POST https://httpbin.org/post wicked=witch casts:='["spells", "curses"]' --json
@sriyanfernando ne fonctionne toujours pas (httpie 0.99, Windows 10x64, Python 3.61, invite de commande Windows standard) :
C:\Users\Me>http post localhost:8000/mail/ recipients:='["[email protected]"]' --json
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
[--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
[--all] [--history-print WHAT] [--stream] [--output FILE]
[--download] [--continue]
[--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
[--auth USER[:PASS]] [--auth-type {basic,digest}]
[--proxy PROTOCOL:PROXY_URL] [--follow]
[--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
[--check-status] [--verify VERIFY]
[--ssl {ssl2.3,ssl3,tls1,tls1.1,tls1.2}] [--cert CERT]
[--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
[--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
[METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: "recipients:='[[email protected]]'": Expecting value: line 1 column 1 (char 0)
@poskadesign Essayez ceci :
http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"
Je ne connais pas très bien la ligne de commande Windows, mais j'ai trouvé https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line qui est similaire.
Commentaire le plus utile
@poskadesign Essayez ceci :
Je ne connais pas très bien la ligne de commande Windows, mais j'ai trouvé https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line qui est similaire.