Httpie: JSON์„ ์ž˜๋ชป ๊ตฌ๋ฌธ ๋ถ„์„

์— ๋งŒ๋“  2017๋…„ 04์›” 13์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: httpie/httpie

์ด๋ด,

์šฐ์„  httpie๋Š” ํ›Œ๋ฅญํ•œ ์†Œํ”„ํŠธ์›จ์–ด์ž…๋‹ˆ๋‹ค. ๋™๋ฃŒ๊ฐ€ ๋ช‡ ๋ช…์ด๋‚˜ ์ถ”์ฒœํ–ˆ๋Š”์ง€ ๊ธฐ์–ต๋‚˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ œ๊ฐ€ ๊ฒช์€ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. JSON ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ œ๊ณตํ•˜๋Š” ์‚ฌ์–‘์— ๋”ฐ๋ฅด๋ฉด := ์—ฐ์‚ฐ์ž๋ฅผ ํ†ตํ•ด ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค์Œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ httpie 0.9.9๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

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

์œ ํšจํ•˜์ง€ ์•Š์€ JSON์— ๋Œ€ํ•œ ๋ฉ”์‹œ์ง€๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ["test string"] ๋Š” ์œ ํšจํ•œ JSON afaik์ž…๋‹ˆ๋‹ค.

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

์–ด์ฉŒ๋ฉด ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ์ž˜๋ชป๋œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด๋Š” ๊ฒƒ์— ๋Œ€ํ•ด ์„ ์„ ๊ธ‹์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๊นŒ?

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

@poskadesign ์ด๊ฒƒ์„ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค:

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

์ €๋Š” Windows ๋ช…๋ น์ค„์— ์ต์ˆ™ํ•˜์ง€ ์•Š์ง€๋งŒ ์œ ์‚ฌํ•œ https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line ์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  7 ๋Œ“๊ธ€

๋‚ด๊ฐ€ ํ‹€๋ ธ๋‹ค๋ฉด ์ •์ •ํ•ด ์ฃผ์„ธ์š”. ํ•˜์ง€๋งŒ JSON ๊ฐ์ฒด๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ {"key":"value"} ํ˜•์‹์ด ์•„๋‹Œ๊ฐ€์š”?

@poskadesign ๋ช…๋ น์€ ๊ดœ์ฐฎ์•„ ๋ณด์ด๊ณ  Bash์—์„œ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์‰˜์„ ์‚ฌ์šฉํ•˜๋ฉด ํƒˆ์ถœ ๋ฌธ์ œ๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

์•ˆ๋…•ํ•˜์„ธ์š”, ์ €๋Š” ์˜คํ”ˆ ์†Œ์Šค ํ”„๋กœ์ ํŠธ์˜ ์ดˆ๋ณด์ž์ž…๋‹ˆ๋‹ค. ์ด ๋ฌธ์ œ์— ๋Œ€ํ•œ ์ž‘์—…์„ ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ด ์ฃผ์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ?

@poskadesign ๊ทธ๊ฒŒ ๋ฌด์Šจ OS์™€ ์‰˜์ธ๊ฐ€์š”? ์‰˜์ด ๊ณต๋ฐฑ์—์„œ ๋‹จ์–ด ๋ถ„ํ• ์„ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด ํฐ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•œ ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด์ง€๋งŒ ์ธ์ˆ˜์— ์ž‘์€ ๋”ฐ์˜ดํ‘œ๋ฅผ ๋‚จ๊ฒผ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๊ตฐ์š”.. http POST https://httpbin.org/post evil=witch casts:='["spells", "curses"]' --json

@sriyanfernando๋Š” ์—ฌ์ „ํžˆ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค(httpie 0.99, Windows 10x64, Python 3.61, ํ‘œ์ค€ Windows ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ):

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 ์ด๊ฒƒ์„ ์‹œ๋„ํ•˜์‹ญ์‹œ์˜ค:

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

์ €๋Š” Windows ๋ช…๋ น์ค„์— ์ต์ˆ™ํ•˜์ง€ ์•Š์ง€๋งŒ ์œ ์‚ฌํ•œ https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line ์„ ์ฐพ์•˜์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰