Pulling out values from a X-Backside-Transport containing xml from USPS api

I am trying to use the shipping calculator from the usps. I have the code working, but the response comes back with this X-Backside-Transport code and I cannot figure out how to pull the xml out and get just the rate.

Below is my code:

<?php  $pounds = 10; $ounces = 2;  $dest_zip = 29651; $originZip = 59759;  //echo USPSParcelRate($weight,$dest_zip);  function USPS($pounds, $ounces, $originZip, $destZip) {      // This script was written by Mark Sanborn at http://www.marksanborn.net     // If this script benefits you are your business please consider a donation     // You can donate at http://www.marksanborn.net/donate.      // ========== CHANGE THESE VALUES TO MATCH YOUR OWN ===========     $username = '698URBAN7869';     // ========== CHANGE THESE VALUES TO MATCH YOUR OWN ===========      $url = "http://Production.ShippingAPIs.com/ShippingAPI.dll";     $ch = curl_init();      // set the target url     curl_setopt($ch, CURLOPT_URL, $url);     curl_setopt($ch, CURLOPT_HEADER, 1);     curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);      // parameters to post     curl_setopt($ch, CURLOPT_POST, 1);      // You would want to actually build this xml using dimensions     // and other attributes but this is a bare minimum request as     // an example.     $data = "API=RateV4&XML=<RateV4Request USERID=\"{$username}\">        <Revision>2</Revision>        <Package ID=\"1ST\">           <Service>PRIORITY</Service>           <ZipOrigination>{$originZip}</ZipOrigination>           <ZipDestination>{$destZip}</ZipDestination>           <Pounds>{$pounds}</Pounds>           <Ounces>{$ounces}</Ounces>           <Container />           <Size>REGULAR</Size>           <Width>2</Width>           <Length>1</Length>           <Height>3</Height>           <Girth>10</Girth>           <Machinable>false</Machinable>        </Package>     </RateV4Request>";      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);      $result = curl_exec ($ch);      return $result; }  var_dump(     USPS(5, 1, '59759', '90210') );      ?>

And this is the response that I get. The xml is in there but there is a bunch of string text that come before with the Background Transport.

string(5446) "HTTP/1.0 200 OK X-Backside-Transport: OK OK Cache-Control: private Content-Type: text/xml Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Fri, 10 Jul 2020 13:51:39 GMT X-Global-Transaction-ID: 3cde8ee25f0872888055d47f Access-Control-Allow-Origin: * Connection: Keep-Alive Content-Length: 5076 X-FRAME-OPTIONS: SAMEORIGIN 597599021051VARIABLE5Priority Mail 3-Day<sup>™</sup>15.70119Adult Signature Requiredtrue6.65120Adult Signature Restricted Deliverytrue6.90104Certificate of Mailing (Form 3817)true1.50105Certified Mail<sup>®</sup>true3.55170Certified Mail<sup>®</sup> Restricted Deliverytrue9.00171Certified Mail<sup>®</sup> Adult Signature Requiredtrue9.00172Certified Mail<sup>®</sup> Adult Signature Restricted Deliverytrue9.00103Collect on Deliverytrue7.85truefalse175Collect on Delivery Restricted Deliverytrue13.15truefalse125Insurancetrue0.00truefalse179Insurance Restricted Deliverytrue0.00truefalse109Registered Mail<sup>™</sup>true12.60truefalse176Registered Mail<sup>™</sup> Restricted Deliverytrue17.90truefalse181Scan Retentiontrue2.10falsefalse108Signature Confirmation<sup>™</sup>true3.15173Signature Confirmation<sup>™</sup> Restricted Deliverytrue8.45156Signature Confirmation<sup>™</sup> Electronictrue2.65174Signature Confirmation<sup>™</sup> Electronic Restricted Deliverytrue7.95190Special Handling – Fragiletrue11.15106USPS Tracking<sup>®</sup>true0.00155USPS Tracking<sup>®</sup> Electronictrue0.00"

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.