OK, I am a beaten man 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