java.io.IOException:流已关闭

时间:2020-08-13 07:27:09

标签: json groovy httprequest response restapi

当我尝试打印来自http连接的响应时,出现以下错误。我想我两次使用流,因此,它说流已关闭但不确定。

我正在尝试使用writeInstFile()打印响应的getInputStream().getText()方法上出现错误

我只是想创建一个新的字符串变量,并将连接流响应放入该变量中并打印出来,以便我可以看到在尝试执行http请求时得到的响应:

    private void writeInstFile(File outFile) {
        Properties config = workflowEnvironment.getConfig()        
        //http connection to get Authentication token
        HttpURLConnection connection = connection("https://XXX/RequestToken")

        if (connection.responseCode == HTTP_OK) {
            String authToken = authTokenFromJson(jsonFromDssRequestTokenConnection(connection))
            log.info("Authentication token: $authToken")
            println(connection.getInputStream().getText());
        if (connection.responseCode == HTTP_OK) {
            println("Got http response code: ${connection.responseCode}, message: ${connection.responseMessage}")

            log.info("Successful DSS request to ${connection.getURL()}")

            LazyMap json = jsonFromDssExtractionConnection(connection)
.....
}


private static String authTokenFromJson(LazyMap json) {
        json.value
    }


private static LazyMap jsonFromDssRequestTokenConnection(HttpURLConnection connection) {
        connection.inputStream.withCloseable { inStream ->
            new JsonSlurper().parse(inStream as InputStream)
        } as LazyMap
    }

0 个答案:

没有答案
相关问题