4
我想从REST资源中使用clj-http版本2.2.0读取JSON,但无论我做什么,我都以字符串的形式得到结果。clj-http不返回JSON
调试时,我剥了下来我在做什么这个请求对我的网络服务器的静态JSON文件上https://nym.at/test.json:
{"foo":1,"bar":"baz"}
我跑在REPL下面的代码(client
绑定到命名空间CLJ-http.client):
(client/get "https://nym.at/test.json" {:as :json :insecure? true})
结果我得到的是(的pritty手动打印):
{:status 200,
:headers {"Server" "Apache/2.4.18 (Debian)",
"Upgrade" "h2,h2c",
"Content-Type" "application/json",
"Content-Length" "22",
"Strict-Transport-Security" "max-age=31536000; includeSubDomains",
"Connection" "Upgrade, close",
"Accept-Ranges" "bytes",
"ETag" "\"16-532fcf29f30c6\"",
"Date" "Mon, 16 May 2016 22:14:59 GMT",
"Last-Modified" "Mon, 16 May 2016 22:14:27 GMT"},
:body "{\"foo\":1,\"bar\":\"baz\"}\n",
:request-time 637,
:trace-redirects ["https://nym.at/test.json"],
:orig-content-encoding nil}
我的期望错了,{:as :json}
应该导致clj-http将响应解析为JSON,并在:body
上回应它,或者我在这里做错了什么?
谢谢,这工作。我一定有错误的文档,因为我认为柴郡是一个依赖,因此希望leiningen自动加载它。 –