Apache HtppClient を使用して HTTP GET を実行し、応答を読み取ろうとしています。私の現在の努力は次のようになります
def listAlertsUrl = "http://example.com/whatever"
HttpGet listAlertsRequest = new HttpGet(listAlertsUrl)
HttpResponse response = httpClient.execute(listAlertsRequest)
HttpEntity entity = response.entity
EntityUtils.consume(entity)
// newReader() is a method that Groovy adds to InputStream
Reader jsonResponse = entity.content.newReader()
try {
// do stuff with the Reader
} finally {
jsonResponse.close()
}
ただし、を使用しようとするとReader
、エラーが発生します。
原因: java.io.IOException: クローズされたストリームから読み取ろうとしました。
HttpClient v.4 の使用例を見つけるのに苦労しています。これは、私の Google 検索では、API がまったく異なる古いバージョンの例しか返されないためです。