如何使用标准库在Groovy中发布JSON



在groovy中只使用标准库将JSON发布到URL的最简单方法是什么?(即,不使用HttpClient或HttpClientBuilder)

这是一个我不想在很多其他库中链接到的脚本。

def con = "http://endpointUrl".toURL().openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json");
con.outputStream.withWriter { writer ->
  writer << jsonString
}
String response = con.inputStream.withReader { Reader reader -> reader.text }

最新更新