腐败。通过 Jenkins 管道中的外部 API 调用的 '.xls' 文件

Getting corrupted. '.xls' file via external API call in Jenkins pipeline

我正在尝试为我的 Jenkins 管道编写一个 groovy 脚本,它调用一个 API 输出一个 '.xls' 文件并将其存储在工作区目录中。 我使用管道语法生成器为 HttpRequest 生成了一个脚本,如下所示。

代码:

def response = httpRequest customHeaders: [[maskValue: false, name: 'Accept', value: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']], outputFile: './abc.xls', url: 'http://xyz/', wrapAsMultipart: false

above-mentioned 代码能够在所需位置下载文件,但文件数据已损坏。 我尝试使用 Jenkins 中可用的默认 content-type/Accept,甚至尝试自定义 header,但其中 none 似乎能够检索正确的“.xls”文件数据。

当尝试使用 PostMan 在 header 中使用 Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 命中 API 时,文件数据以正确的格式接收,文件没有损坏。

谁能帮我弄清楚这里的确切问题是什么?

contentType设置请求格式,而acceptType定义响应格式。尝试按如下方式设置 acceptType

def response = httpRequest url: "https:/....", httpMode: 'POST', 
    contentType: 'APPLICATION_JSON', 
    requestBody: JsonOutput.toJson(bodyParameters),
    acceptType: 'APPLICATION_OCTETSTREAM',
    outputFile: "${REPORT_FILE_NAME_COMPLETE_PATH}"