Forum Moderators: coopster
I tried using the SimpleXML but I encountered the following error message;
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Start tag expected, '<' not found in /home/content/a/u/g/test/html/example/ratelookup.php on line 158
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: HTTP/1.1 200 OK in /home/content/a/u/g/test/html/example/RatePackage.php on line 158
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in /home/content/a/u/g/test/html/example/RatePackage.php on line 158
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/content/a/u/g/test/html/example/RatePackage.php:158 Stack trace: #0 /home/content/a/u/g/test/html/example/RatePackage.php(158): SimpleXMLElement->__construct('HTTP/1.1 200 OK...') #1 /home/content/a/u/g/test/html/library/functions.php(175): include('/home/content/a...') #2 /home/content/a/u/g/test/html/cart.php(24): shippingTaxCalculator('75069') #3 {main} thrown in /home/content/a/u/g/test/html/example/RatePackage.php on line 158
I believe it is occuring because I have to get a substring of the response to get to the XML due to the fact that "HTTP/1.1 200 OK Server: Sun-ONE-Web-Server/6.1 Date: Tue, 01 Apr 2008 03:24:22 GMT Content-length: 2546 Content-type: text/xml; charset=utf-8 X-Powered-By: Servlet/2.4 JSP/2.0 " appears before the first XML tag is encountered within the response.
However I noticed that getting a substring appears to have it's own set pf problems because the first '<' is evaluted as '<'.
Do you know how I can access the XML for this string so that I can parse through it properly?
Thank you!
Even though I have eliminated the need to run a substring, I am still unable to parse the response to retrieve the shipping rate (below is a snapshot of my code for your reference).
FYI - I was initially running the request via SOAP however my hosting account doesn't allow me to run the request directly so I have run it through a proxy. I tried to specify a proxy via SOAP however my request would always fail so I decided to use cURL (which might be a bad idea since my response is not in XML).
Do you know what might be causing the issue?
Thank you!
$FedExRateRequest = <<< XMLREQUEST
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v3">
<SOAP-ENV:Body>
<ns1:RateRequest>
<ns1:WebAuthenticationDetail>
<ns1:UserCredential>
<ns1:Key>123456</ns1:Key>
<ns1:Password>987654</ns1:Password>
</ns1:UserCredential>
</ns1:WebAuthenticationDetail>
<ns1:ClientDetail>
<ns1:AccountNumber>11111111</ns1:AccountNumber>
<ns1:MeterNumber>111111</ns1:MeterNumber>
</ns1:ClientDetail>
<ns1:TransactionDetail>
<ns1:CustomerTransactionId>123345433</ns1:CustomerTransactionId>
</ns1:TransactionDetail>
<ns1:Version>
<ns1:ServiceId>crs</ns1:ServiceId>
<ns1:Major>3</ns1:Major>
<ns1:Intermediate>0</ns1:Intermediate>
<ns1:Minor>0</ns1:Minor>
</ns1:Version>
<ns1:Origin>
<ns1:StreetLines>100 Test Street</ns1:StreetLines>
<ns1:City>Cincinatti</ns1:City>
<ns1:StateOrProvinceCode>OH</ns1:StateOrProvinceCode>
<ns1:PostalCode>45241</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Origin>
<ns1:Destination>
<ns1:StreetLines/>
<ns1:City/>
<ns1:StateOrProvinceCode/>
<ns1:PostalCode>75243</ns1:PostalCode>
<ns1:CountryCode>US</ns1:CountryCode>
</ns1:Destination>
<ns1:Payment>
<ns1:PaymentType>SENDER</ns1:PaymentType>
</ns1:Payment>
<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>
<ns1:ServiceType>$shippingServiceType</ns1:ServiceType>
<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>
<ns1:ShipDate>$currentDate</ns1:ShipDate>
<ns1:RateRequestTypes>ACCOUNT</ns1:RateRequestTypes>
<ns1:PackageCount>1</ns1:PackageCount>
<ns1:Packages>
<ns1:InsuredValue>
<ns1:Currency>USD</ns1:Currency>
<ns1:Amount>0</ns1:Amount>
</ns1:InsuredValue>
<ns1:Weight>
<ns1:Units>LB</ns1:Units>
<ns1:Value>40</ns1:Value>
</ns1:Weight>
<ns1:Dimensions>
<ns1:Length>0</ns1:Length>
<ns1:Width>0</ns1:Width>
<ns1:Height>0</ns1:Height>
<ns1:Units>IN</ns1:Units>
</ns1:Dimensions>
<ns1:SpecialServicesRequested>
<ns1:SpecialServiceTypes>NON_STANDARD_CONTAINER</ns1:SpecialServiceTypes>
</ns1:SpecialServicesRequested>
</ns1:Packages>
</ns1:RateRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
XMLREQUEST;
$submiturl = "https://example.test.com:443/web-services";
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $submiturl);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.xyz.secureserver.net:3128");
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $FedExRateRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
$FedExRateResponse = curl_exec($ch);
if (curl_error($ch))
{
$EmailErrorSubject = 'Concession Palace - FedEx Exception Error';
$EmailErrorMessage = "Errors were encountered: " . curl_errno($ch) . curl_error($ch);
$EmailErrorMessage += ' - occurred at ' . date('c');
mail('webmaster@example.com',$EmailErrorSubject,$EmailErrorMessage,'From: webmaster@example.com');
curl_close($ch);
$_SESSION['ShippingZipCode'] = "";
header('Location: error.php');
}
else
{
curl_close($ch);
$FedExRateResponseXML = htmlentities($FedExRateResponse);
$_SESSION['ShippingCost'] = $FedExRateResponseXML->{'v3:RateReply'}->{'v3:RatedShipmentDetails'}->{'v3:ShipmentRateDetail'}->{'v3:TotalNetCharge'}->{'v3:Amount'};
}
print_r($FedExRateResponseXML);
[edited by: eelixduppy at 4:14 am (utc) on April 2, 2008]
[edit reason] exemplified [/edit]
htmlentities [us.php.net] - Convert all applicable characters to HTML entities
Now that you've got the header stuff stripped off try your script without it.
SUCCESSSUCCESScrs0Request was successfully processedRequest was successfully processed sid_6e3cq4q2n29de3ckrua84j29g7_d_2008-04-02_z_75243 crs 3 0 0 falseA2A2TWO_DAYSSERVICE_DEFAULTPAYOR_ACCOUNTPAYOR_ACCOUNT506.0LB20.0USD9.51USD0.0USD9.51USD7.07USD0.0USD16.58USD0.0
I am not sure how I can convert it into a format that I can easily parse through (unless there is a way I can parse it without formating the string). Any suggestions will be greatly appreciated.
Thank you!
You could probably define the namespace in the response, but to me it's easier to just yank it out. Change the 'ns1:' in the regular expression to the namespace in the response (looks from your post that it's v3:) and see how that goes.
SUCCESSSUCCESScrs0Request was successfully processedRequest was successfully processed sid_6e3cq4q2n29de3ckrua84j29g7_d_2008-04-02_z_75243 crs 3 0 0 falseA2A2TWO_DAYSSERVICE_DEFAULTPAYOR_ACCOUNTPAYOR_ACCOUNT506.0LB20.0USD9.51USD0.0USD9.51USD7.07USD0.0USD16.58USD0.0
I have tried several things to try and get it to work (without any success).
Is there an parameter in cURL that I can specify to return a response in XML?
Thank you!
foreach ($response -> RatedShipmentDetails as $RatedShipmentDetails)
{
if(is_array($response -> RatedShipmentDetails))
{
echo $RatedShipmentDetails -> ShipmentRateDetail->TotalNetCharge->Currency;
echo ': ';
echo $RatedShipmentDetails -> ShipmentRateDetail->TotalNetCharge->Amount . $newline;
}
else
{
echo $RatedShipmentDetails . $newline;
}
}
Now, I need some help. This is my XML schema.
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v3">
<SOAP-ENV:Body><ns1:RateRequest>
<ns1:WebAuthenticationDetail>
<ns1:UserCredential>
<ns1:Key>yeFlflsOfHknbEGC</ns1:Key>
<ns1:Password>9Nng0sY4l6Jg9wkdeKnKAv3YT</ns1:Password>
</ns1:UserCredential>
</ns1:WebAuthenticationDetail>
<ns1:ClientDetail>
<ns1:AccountNumber>510087860</ns1:AccountNumber>
<ns1:MeterNumber>1229519</ns1:MeterNumber>
</ns1:ClientDetail>
<ns1:TransactionDetail>
<ns1:CustomerTransactionId>5682345</ns1:CustomerTransactionId>
</ns1:TransactionDetail>
<ns1:Version>
<ns1:ServiceId>crs</ns1:ServiceId>
<ns1:Major>3</ns1:Major>
<ns1:Intermediate>0</ns1:Intermediate>
<ns1:Minor>0</ns1:Minor>
</ns1:Version>
<ns1:Origin>
<ns1:StreetLines>Sender Address Line 1</ns1:StreetLines>
<ns1:PostalCode>149063</ns1:PostalCode>
<ns1:CountryCode>SG</ns1:CountryCode>
</ns1:Origin>
<ns1:Destination>
<ns1:StreetLines>Destination Address Line 1</ns1:StreetLines>
<ns1:PostalCode>700050</ns1:PostalCode>
<ns1:CountryCode>IN</ns1:CountryCode>
</ns1:Destination>
<ns1:Payment>
<ns1:PaymentType>SENDER</ns1:PaymentType>
</ns1:Payment>
<ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType>
<ns1:ServiceType>INTERNATIONAL_PRIORITY</ns1:ServiceType>
<ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType>
<ns1:ShipDate>2008-04-05</ns1:ShipDate>
<ns1:RateRequestTypes>LIST</ns1:RateRequestTypes>
<ns1:RateRequestPackageSummary>
<ns1:PieceCount>2</ns1:PieceCount>
<ns1:TotalWeight><ns1:Units>LB</ns1:Units>
<ns1:Value>20</ns1:Value>
</ns1:TotalWeight>
<ns1:TotalInsuredValue>
<ns1:Currency>USD</ns1:Currency>
<ns1:Amount>100</ns1:Amount>
</ns1:TotalInsuredValue>
<ns1:SpecialServicesRequested>
<ns1:SpecialServiceTypes>NON_STANDARD_CONTAINER</ns1:SpecialServiceTypes>
</ns1:SpecialServicesRequested>
</ns1:RateRequestPackageSummary>
</ns1:RateRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I am getting this ::
Error in processing transaction.
FAILURE
crs
999
Internal or unexpected error
Internal or unexpected error
Any help will be appreciated.