cURLを使用する私はボディでGETリクエストを送信できます。例:ここではHTTPBuilderはGETメソッドでrequestBodyを設定します
curl -i -X GET http://localhost:8081/myproject/someController/l2json -H "content-type: application/json" -d "{\"stuff\":\"yes\",\"listThing\":[1,2,3],\"listObjects\":[{\"one\":\"thing\"},{\"two\":\"thing2\"}]}"
はJSONは読みやすさのために合理的な形式である:
{"stuff":"yes",
"listThing":[1,2,3],
"listObjects":[{"one":"thing"},{"two":"thing2"}]}
通常-d
はPOSTを送信するためにカールを教えてくれますが、私は-X GET
はそれをオーバーライドしていることを確認していると、それはありますGETを送信します。 HTTPBuilderでこれを複製することは可能ですか?
は、私が行っている:
動作しますが、私は.post
.get
に変更した場合、私はエラーを取得
def http = new HTTPBuilder('http://localhost:8081/')
http.post(path:'/myproject/myController/l2json', body:jsonMe, requestContentType:ContentType.JSON) { resp ->
println "Tweet response status: ${resp.statusLine}"
assert resp.statusLine.statusCode == 200
}
:
Cannot set a request body for a GET method. Stacktrace follows:
Message: Cannot set a request body for a GET method
Line | Method
->> 1144 | setBody in groovyx.net.http.HTTPBuilder$RequestConfigDelegate
使用して要求本体とGETを送信する方法はありますがHTTPBuilder?