0

Basically, I am using http-request-plugin to send http-request in jenkins-pipeline.

In this post, it is possible to send JSON-encoded http-body in http-get method. However, the http-body is empty in the server-side when running the below jenkins-pipeline script. Is it allowed to send JSON-data in http-body when using http-get method?

import groovy.json.JsonOutput

def reqBody = [
  'key01': 'val01',
  'key02': 'val02',
]
def resp = httpRequest(
  url: '127.0.0.1:8000/api/service01',
  httpMode: 'GET',
  contentType: 'APPLICATION_JSON',
  requestBody: JsonOutput.toJson(reqBody),
)
Hobin C.
  • 671
  • 1
  • 8
  • 17

1 Answers1

0

One possible solution is to refactor the script in the server-side to read parameters in http-post. After this, the http-body has the json-data.

import groovy.json.JsonOutput

def reqBody = [
  'key01': 'val01',
  'key02': 'val02',
]
def resp = httpRequest(
  url: '127.0.0.1:8000/api/service01',
  httpMode: 'POST',
  contentType: 'APPLICATION_JSON',
  requestBody: JsonOutput.toJson(reqBody),
)
Hobin C.
  • 671
  • 1
  • 8
  • 17