0
getメソッド(HttpGetJson)を呼び出して応答値を返し、resp(応答コード用)およびjson(コンテンツ用)値を取得するために使用します。しかし、私はresponse.successとは別にrespとjsonを返すときだけ有効な出力を得ます。私が応答オブジェクトを返そうとすると、私はNULLだけを取得します。レスポンスを返す方法はありますか?HTTPBuilderを使用したREST APIの応答の取得
public static Object HttpGetJson(String url, String path)
def http = new HTTPBuilder(url)
//perform a GET request, expecting JSON response
http.request(GET,JSON) { req ->
uri.path = path
//response handler for a success response code
response.success = { resp, json ->
return response//using response instead of json or resp returns null
}
}
public void testGET()
{
def url = 'testurl'
def path = 'testpath'
//submit a request through GET
def response1 = HttpUtils.HttpGetJson(url,path)
println response1
//println response.statusLine.statusCode
}
働い:
IMOあなたは
response.success
から実行するクロージャを渡す必要があります。ありがとう! – Rebeller