PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Mon Feb 21, 2005 3:32 pm
I am trying to send xml to usps to retreive shipping rates for a shopping cart. But I am having a hard time getting the request out.
Code: Select all
$filename = "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Request USERID="test" PASSWORD="test"><Package ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat Rate Box</Container><Size>REGULAR</Size></Package></RateV2Request>";
$xml = simplexml_load_file($filename);
echo $xml->RateV2Responseї0]->Rate;It keeps giving me a 400 Bad Request.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 3:33 pm
rawurlencode() the XML.
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Mon Feb 21, 2005 3:58 pm
Code: Select all
<?php
$filename = "http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=" . rawurlencode('<RateV2Request USERID="877BACK46071" PASSWORD="409BK65DW159"><Package ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat Rate Box</Container><Size>REGULAR</Size></Package></RateV2Request>');
$xml = simplexml_load_file($filename);
echo $xml->RateV2Responseї0]->Packageї0]->Postageї0]->Rate;
?>Nope still gives me "HTTP request failed! HTTP/1.1 400 Bad Request"
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 4:03 pm
..and you're sure about the url being valid? no case issues?
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Mon Feb 21, 2005 4:08 pm
yea if you put the link in the browser it works just fine.
I added htmlspecialchars and now it comes up with no errors but no rate. Here is what it sends back do I have my simple xml set right to read it:
Code: Select all
<?xml version="1.0"?>
<RateV2Response>
<Package ID="0">
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination>
<Pounds>10</Pounds>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size>
<Zone>3</Zone>
<Postage>
<MailService>Priority Mail Flat Rate Box (11.25" x 8.75" x 6")</MailService>
<Rate>7.70</Rate>
</Postage>
<Postage>
<MailService>Priority Mail Flat Rate Box (14" x 12" x 3.5")</MailService>
<Rate>7.70</Rate>
</Postage>
</Package>
</RateV2Response>Code: Select all
$xml->RateV2Responseї0]->Packageї0]->Postageї0]->Rate;
Last edited by
bdeonline on Mon Feb 21, 2005 4:18 pm, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Feb 21, 2005 4:17 pm
on my machine
Code: Select all
<?php
$data = file_get_contents('http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=' . rawurlencode('<RateV2Request USERID="877BACK46071" PASSWORD="409BK65DW159"><Package ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat Rate Box</Container><Size>REGULAR</Size></Package></RateV2Request>'));
var_export($data);
?>outputs:
Code: Select all
'<?xml version="1.0"?>
<RateV2Response><Package ID="0"><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat Rate Box</Container><Size>REGULAR</Size><Zone>3</Zone><Postage><MailService>Priority Mail Flat Rate Box (11.25" x 8.75" x 6")</MailService><Rate>7.70</Rate></Postage><Postage><MailService>Priority Mail Flat Rate Box (14" x 12" x 3.5")</MailService><Rate>7.70</Rate></Postage></Package></RateV2Response>'
bdeonline
Forum Commoner
Posts: 42 Joined: Sun Jul 18, 2004 10:45 am
Post
by bdeonline » Mon Feb 21, 2005 4:21 pm
Yea thats working here as well so is it just "simplexml_load_file". Not sending the request right or can it not do remote request.