【问题标题】:How can you perform an HTTP POST with a binary file in Jenkins?如何在 Jenkins 中使用二进制文件执行 HTTP POST?
【发布时间】:2019-06-22 04:02:55
【问题描述】:

我想执行二进制文件的 HTTP POST,就像我在 Postman 中这样:

注意这里我选择了 HTTP Post,带有二进制选项,并标记了我的文件“splop.sar”。

服务器回复 http 409,这是我的用例所期望的。

我在 Jenkins 中的尝试如下,使用 httpRequest 插件:

def myFile = readFile("splop.sar")
httpRequest authentication: 'userdef', consoleLogResponseBody: true, contentType: 'APPLICATION_ZIP', httpMode: 'POST', requestBody: myFile, responseHandle: 'NONE', url: 'myurl.com/service'

问题是,我的后端服务器拒绝了无效的请求,毫无疑问编码在这里失败了。我已经尝试过替代方法,例如:

def myFile = readFile("splop.sar").bytes

也失败了,还有:

def myFile = readFile("splop.sar").bytes.toString()

这也失败了!

我可以在 Jenkins 中做些什么来提供与邮递员在我的管道中提供的相同样式的 HTTP Post?我相信这里最大的区别是是什么使 POST 请求成为“二进制”帖子,而不是其他形式?

【问题讨论】:

    标签: java jenkins groovy jenkins-pipeline


    【解决方案1】:

    我不认为你可以用 http-request-plugin 做到这一点,有一个open bug for that

    你绝对可以用 curl 做到这一点 - Send POST Request with Data Specified in File via Curl

    curl -i -X POST host:port/post-file \
      -H "Content-Type: text/xml" \
      --data-binary "@path/to/file"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      相关资源
      最近更新 更多