clj-http 0.4.0库似乎没有正确发送JSON参数;但它应该在0.3.4中修补:
很难准确说出发送的是什么,因为在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})
Netcat输出......
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})
Netcat输出......
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的第一次回合,所以我可能会遗漏一些东西 - 发生了什么?
答案 0 :(得分:2)
这是最近对嵌套表单参数的拉取请求中引入的错误。我在这里修好了:https://github.com/dakrone/clj-http/commit/2e5aab82029b46f0b1e28d53734c642582306539