Returned XML displayed, another XML not displayed by echo/print_r



I am slowly building a USPS (US Postal Service) application. Limited experience with CURL and XML.


I am trying to grab an XML response but on a longer response I seem to get back nothing.


I am now stuck. I tried pasting the URL from the CURL into an address bar to deliberately get something to work with - ie the error messages below. But one displays as expected and the other displays nothing.


Both seem to be well formed XML.


I am missing something not sure what.


With one deliberate error I get back:



<Error>
<Number>80040B19</Number>
<Description>
XML Syntax Error: Please check the XML request to see if it can be parsed.
</Description>
<Source>USPSCOM::DoAuth</Source>
</Error>


with the second I get back:



<RateV4Response>
<Package ID="3RD">
<Error>
<Number>-2147219503</Number>
<Source>RateEngineV4;RateV4.ProcessRequest</Source>
<Description>Please enter a valid weight in pounds.</Description>
<HelpFile/>
<HelpContext/>
</Error>
</Package>
</RateV4Response>


these are handled by this bit of code:



if ($_POST['getMailPrice']=="yes")
{echo "hello";
$curl=curl_init($url);
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($curl);
print_r ($result);
echo "<h1>$result</h1>";
}


What I am completely stumped by is with the first "error" I get exactly what I would expect - ie the print_r and the echo display exactly as I would expect. With the second there is nothing displayed at all.


(I don't think the URLs are very relevant as it is the XML coming back that is important (I think)). Anyway the URLS in question are:



$url="production.shippingapis.com";


which gives the first error and



$url="http://ift.tt/1wqrjoI USERID='99999999'><Revision/><Package ID='3RD'><Service>ALL</Service><ZipOrigination>90210</ZipOrigination><ZipDestination>96698</ZipDestination><Pounds></Pounds><Ounces></Ounces><Container/><Size>REGULAR</Size><Machinable>true</Machinable><DropOffTime>23:59</DropOffTime><ShipDate>2013-07-28</ShipDate></Package></RateV4Request>";


Which gives the second.


No comments:

Post a Comment