Httpie: Falsches Parsen von JSON

Erstellt am 13. Apr. 2017  ·  7Kommentare  ·  Quelle: httpie/httpie

Hey,

Zunächst einmal ist httpie eine großartige Software. Ich kann mich nicht erinnern, wie vielen Kollegen ich es empfohlen habe.

Ich bin auf ein Problem gestoßen. Gemäß der Spezifikation erfolgt die Bereitstellung von JSON-Parametern über den Operator := . Aber starten Sie httpie 0.9.9 mit diesen Parametern:

http post localhost/example/ param1="a b c" param2=d jparam:='["test string"]'

Führt zu einer Nachricht über ungültiges JSON. Aber ["test string"] ist ein gültiger JSON-Afaik.

http: error: "jparam:='[test string]'": Expecting value: line 1 column 1 (char 0)

Vielleicht kann jemand etwas sagen, was falsch zu sein scheint?

Hilfreichster Kommentar

@poskadesign Versuchen Sie dies:

http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"

Ich bin mit der Windows-Befehlszeile nicht sehr vertraut, habe aber https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line gefunden, die ähnlich ist.

Alle 7 Kommentare

Korrigieren Sie mich, wenn ich falsch liege, aber hat ein JSON-Objekt normalerweise nicht das Format {"key":"value"}?

@poskadesign der Befehl sieht in Ordnung aus und funktioniert bei mir in Bash. Es könnte ein Fluchtproblem sein, wenn Sie eine andere Shell verwenden.

$ 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"
}

Hallo, ich bin ein Neuling in Open Source Projekten. Ich möchte an diesem Thema arbeiten. Könnten Sie mir bitte weitere Informationen zukommen lassen?

@poskadesign Welches Betriebssystem und welche Shell ist das? Es sieht so aus, als ob Ihre Shell die doppelten Anführungszeichen verwendet hat, um eine Worttrennung im Leerzeichen zu vermeiden, aber dann die einfachen Anführungszeichen im Argument belassen hat.

Es ist ungefähr so.. http POST https://httpbin.org/post wicked=witch casts:='["spells", "curses"]' --json

@sriyanfernando funktioniert immer noch nicht (httpie 0.99, Windows 10x64, Python 3.61, Standard-Windows-Eingabeaufforderung):

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 Versuchen Sie dies:

http post localhost/example/ param1="a b c" param2=d jparam:="[\"test string\"]"

Ich bin mit der Windows-Befehlszeile nicht sehr vertraut, habe aber https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line gefunden, die ähnlich ist.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen