使用cURL我可以發送一個帶有body的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
會告訴捲曲發送一個職位,但我已經證實,-X GET
壓倒一切的是,它是發送GET。 HTTPBuilder是否可以複製它?
我做:
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
}
其中一期工程,但如果我改變.post
到.get
我得到的錯誤:
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?