How to send a HTTP Post request using PHP Curl and WordPress

I managed to solve this by adding the following into my functions.php

add_shortcode('my_shortode', 'my_function');
function my_function () {


$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "2222",
  CURLOPT_URL => "http://11.111.11.111:2222/folder/query",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "<root>\r\n  <something1>username</something1>\r\n  <something2>123456789</something2>\r\n  <something3>Hello</something3>\r\n</root>\r\n",
  CURLOPT_HTTPHEADER => array(
    "Accept: application/xml",
    "Cache-Control: no-cache",
    "Connection: keep-alive",
    "Content-Type: application/xml",
    "Host: 80.177.77.210:2222",
    "Postman-Token: ",
    "User-Agent: ",
    "accept-encoding: gzip, deflate",
    "cache-control: no-cache",
    "content-length: 107"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
}

Then in my page template

<?php echo do_shortcode( '[my_shortode]' ); ?>