3

I would like to perform an HTTP POST of a Binary file, as I would from Postman like this:

enter image description here

Note here I have selected HTTP Post, with the binary option, and flagged my file "splop.sar".

The server replies http 409 which is expected for my use case.

My attempt in Jenkins has been as follows, using the httpRequest plugin :

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

The problem is, my backend server rejects the request as invalid, no doubt the encoding has failed here. I have tried alternatives such as:

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

Which also fails, as well as:

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

Which also fails!

What can I do within Jenkins to provide the same style of HTTP Post that postman is giving from within my pipeline? I believe the big difference here is what makes the POST request a 'binary' post, against some other form?

RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130

2 Answers2

2

I don't think you can do it with http-request-plugin, there's an open bug for that.

You could definitely do that with 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"
hakamairi
  • 4,464
  • 4
  • 30
  • 53
2

The httpRequest plugin has got a parameter uploadFile which is a path to the file you want to upload. See documentation https://www.jenkins.io/doc/pipeline/steps/http_request/ (Available since release 1.14 which is quite new)