์ด๋ด,
์ฐ์ 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)
์ด์ฉ๋ฉด ๋๊ตฐ๊ฐ๊ฐ ์๋ชป๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ ๊ฒ์ ๋ํด ์ ์ ๊ธ์ ์ ์์ต๋๊น?
๋ด๊ฐ ํ๋ ธ๋ค๋ฉด ์ ์ ํด ์ฃผ์ธ์. ํ์ง๋ง 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 ์ ์ฐพ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@poskadesign ์ด๊ฒ์ ์๋ํ์ญ์์ค:
์ ๋ Windows ๋ช ๋ น์ค์ ์ต์ํ์ง ์์ง๋ง ์ ์ฌํ https://stackoverflow.com/questions/17205292/quotes-around-quotes-in-windows-command-line ์ ์ฐพ์์ต๋๋ค.