clj-http 0.4.0 库似乎没有正确发送 JSON 参数;但是,它应该在 0.3.4 中进行修补:
- https://github.com/dakrone/clj-http/pull/52
- https://github.com/dakrone/clj-http/blob/master/changelog.org
很难准确判断发送的是什么,因为在 clj-http 请求选项中设置debug
为true
将请求参数显示为:
:body #<StringEntity org.apache.http.entity.StringEntity@714c7f58>
为什么不以可视形式显示它们?
所以我使用 netcat 查看发送的内容,这就是它显示的内容:
这有效...
(client/request
{:method :post
:url "http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script"
:body (json/generate-string {:script "g.v(id)", :params {:id 321} })
:content-type :json})
网猫输出...
POST /db/data/ext/GremlinPlugin/graphdb/execute_script HTTP/1.1
Content-Type: application/json; charset=UTF-8
Connection: close
Accept-Encoding: gzip, deflate
Content-Length: 50
Host: localhost:7474
User-Agent: Apache-HttpClient/4.1.3 (java 1.5)
"{\"params\":{\"id\":321},\"script\":\"g.v(id)\"}"
这行不通...
(client/request
{:method :post
:url "http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script",
:form-params {:script "g.v(id)", :params {:id 321}}
:content-type :json})
网猫输出...
POST /db/data/ext/GremlinPlugin/graphdb/execute_script HTTP/1.1
Content-Type: application/json; charset=UTF-8
Connection: close
Accept-Encoding: gzip, deflate
Content-Length: 37
Host: localhost:7474
User-Agent: Apache-HttpClient/4.1.3 (java 1.5)
{"params[id]":321,"script":"g.v(id)"}
这是我第一次使用 Clojure 和 clj-http,所以我可能遗漏了一些东西——发生了什么?