【问题标题】:Getting soapUI to show attachment in attachments tab for a response让soapUI在附件选项卡中显示附件以获取响应
【发布时间】:2012-08-29 19:57:37
【问题描述】:

我有一个通过 HTTP GET 返回文件的 REST 服务。

我已经在响应中(在服务器上)设置了这些标头,并且下载在任何浏览器中都能完美运行:
Content-Length
Content-Type
Content-Disposition


然而,在soapUI中,它只是将二进制输出打印到响应窗口——我想把文件放到底部的“附件”选项卡中。

我尝试过 multipart/mixed 无济于事。

有人知道我应该如何让服务器形成响应,以便soapUI 将文件放在附件选项卡中吗?

谢谢!

【问题讨论】:

    标签: http soapui


    【解决方案1】:

    我不知道如何将文件放在附件选项卡中,但我知道您可以通过 groovy 将二进制输出转换为文件。

    你可以试试这个脚本,只需填写三个变量extension,name,textBase64即可。

    import org.apache.commons.codec.binary.Base64
    def extension = (##extension of your file##)
    def name = (##name of your file ##) 
    def textBase64 =(##binary output from your request##) 
    
    
    // Access element Base64-encoded text content 
    String tempFilename = "${name}.${extension}"
    def b64 = new Base64()
    def TextBytes = b64.decode(textBase64.getBytes())
    
    // Output text into a temporary file
    def File = new java.io.File(tempFilename)
    FileOutputStream fos = new java.io.FileOutputStream(File)
    fos.write( TextBytes )
    fos.flush()
    fos.close()
    log.info "File stored as: ${File.getCanonicalPath()}"
    

    可能存在更好的脚本,但这个对我来说效果很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多