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을 수 있습니다 :
일반적으로-d
{"stuff":"yes",
"listThing":[1,2,3],
"listObjects":[{"one":"thing"},{"two":"thing2"}]}
가 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?