如何使用SOAPUI解压缩GET响应

时间:2019-06-05 18:17:31

标签: groovy get http-headers compression soapui

我收到来自服务器的压缩响应。

with 使用CURL和| gunzip可以得到解压缩的内容响应,但是我不想使用CURL并直接通过SOAPUI,标头或脚本将其解压缩。

我试图写类似的东西:

def responseBody=testRunner.testCase.getTestStepByName("getZIp").httpRequest.response.responseContent;
InputStream ins = new ByteArrayInputStream(responseBody.getBytes())

    log.info responseBody
    def outFile = new FileOutputStream(new File('/users/trythis.zip'))
    if (ins) {
    com.eviware.soapui.support.Tools.writeAll(outFile, ins )
    }
    ins.close()
    outFile.close()

但数据仍处于压缩状态。

2 个答案:

答案 0 :(得分:1)

简单明了的东西

InputStream ins = new ByteArrayInputStream(responseBody.getBytes())
def outFile = new File('/users/trythis.txt')
new GZIPInputStream( ins ).withReader{ outFile << it }

答案 1 :(得分:1)

在SoapUI的首选项中,有一些用于处理API的选项,这些API期望压缩的有效载荷和/或发送回压缩的响应。

我以前使用过此方法,SoapUI解压缩了响应并将其呈现在UI中,因此我不必借助Groovy脚本来读取响应。