How to add variables in the code below

OK, I am a beaten man :wink: I just cannot see where I am going wrong.

I am building a http POST, adding headers and a body, but the moment I try to add variables in the body section, it fails on me. I cannot even do a simple echo, so I am not applying the correct syntax.

The “original” text that is supposed to work OK is below. I need to replace the raw base64 entry with a variable, and also insert the filename of the xml file that was encoded. Can you see where I have gone wrong -

original text -
$request = new HttpRequest();
$request->setUrl(‘https://beta.messagexchange.com/API/SendMessage_Auth’);
$request->setMethod(HTTP_METH_POST);

$request->setQueryData(array(
‘P’ => ‘7ed6d1fe15ce40138f0e7c74397fc9b3’
));

$request->setHeaders(array(
‘cache-control’ => ‘no-cache’,
‘sender-id’ => ‘fiscalsoftware_51’,
‘authorization’ => ‘Basic ZmlzY2Fsc29mdHdhcmVfNTE6Z0pWUnhhR2dkU0RqM0ozRA==’
));

$request->setBody('Content-Type: multipart/mixed; boundary="------------090400040208000301070705"
Subject: STP XML

--------------090400040208000301070705
Content-Transfer-Encoding: 7bit
Content-Type: text/xml; charset=us-ascii

67094544519 Business TEST.0002.0002 Submit.003.00
--------------090400040208000301070705
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=“TEST.0002.0002.xml”
Payloadname: STP_XML

PFJvb3QgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt

I cut a big chunk out of here for readability

t2xkaW5nPg0KCQk8L3RuczpQYXllZT4NCgk8L3RuczpQQVlFVk5U
RU1QPg0KPC9Sb290Pg==

--------------090400040208000301070705–’);

try {
$response = $request->send();

echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}

My Code -
$request = new HttpRequest();
$request->setUrl(‘https://beta.messagexchange.com/API/SendMessage_Auth’);
$request->setMethod(HTTP_METH_POST);

$request->setQueryData(array(
‘P’ => ‘7ed6d1fe15ce40138f0e7c74397’
));

$request->setHeaders(array(
‘cache-control’ => ‘no-cache’,
‘sender-id’ => ‘fiscalsoftware’,
‘authorization’ => ‘Basic ZmlzY2Fsc29mdHdhcmVfNTE6Z0pWUnhhR2dkU0RqM==’
));

$request->setBody('Content-Type: multipart/mixed; boundary="------------090400040208000301070705"
Subject: STP XML

--------------090400040208000301070705
Content-Transfer-Encoding: 7bit
Content-Type: text/xml; charset=us-ascii

67094544519 Business TEST.0002.0002 Submit.003.00
--------------090400040208000301070705
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="’.$xml_file_name.’"
Payloadname: STP_XML
‘.$encoded_xml_file.’

--------------090400040208000301070705–’);
//$input = $request->all();
//echo $input."
";
echo “hello World”;

try {
$response = $request->send();

echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}

Everything compiles ok but it never gets to the simple echo “Hello World”; so it is $xml_file_name and $encoded_xml_file that are the two variables.

So where am I going wrong? Is it the " and ’ combinations, or the . or all three. I just cannot seem to get it right. PS. I have changed the the passwords etc for security considerations. But that should not be an issue.

Thanks
Tony

Ok, I have found that it does not process after

$request = new HttpRequest();

So maybe there is a library I need to add?

Tony