Jump to content

Connecting and Posting to UPS XML Server


jakester

Recommended Posts

I got all these XML templates from UPS to post relevant shipping data from our site to UPS's so they can calculate shpping costs thenPOST it back to us so we can add it to the sale price. I understand the templates well enough, but how do you use the HTTP POST to get the XML to UPS's site? I can't find one example of this anywhere. Then I found some javascript stuff on W3Schools, using the XMLHttpRequest & Microsoft.XMLHTTP objects, but those JS objects won't work in any of my browsers. Please give me a hint. I am pretty good with FORMS and PHP and HTML but new to XML this is the authorization xml you include in the post, you inlcude both in the

 <?xml version="1.0"?><AccessRequest xml:lang="en-US">   <AccessLicenseNumber>XXXXXXXXX</AccessLicenseNumber>   <UserId>dougword</UserId>   <Password>*******</Password></AccessRequest>

Here is the template that UPS gives you:

<?xml version="1.0"?><RatingServiceSelectionRequest xml:lang="en-US">  <Request>    <TransactionReference>      <CustomerContext>Bare Bones Rate Request</CustomerContext>      <XpciVersion>1.0</XpciVersion>    </TransactionReference>	<RequestAction>Rate</RequestAction>	<RequestOption>Rate</RequestOption>  </Request>    <PickupType>  	<Code>01</Code>  </PickupType>  <Shipment>    <Shipper>      	<Address>        	<PostalCode>44129</PostalCode>        	<CountryCode>US</CountryCode>      	</Address>    </Shipper>	    <ShipTo>      	<Address>        	<PostalCode>44129</PostalCode>        	<CountryCode>US</CountryCode>      	</Address>   	</ShipTo>   	<ShipFrom>      	<Address>        	<PostalCode>32779</PostalCode>        	<CountryCode>US</CountryCode>      	</Address>  	</ShipFrom>  	<Service>    		<Code>01</Code>  	</Service>  	<Package>      	<PackagingType>	        <Code>02</Code>      	</PackagingType>			<Dimensions>      			<UnitOfMeasurement>      			  <Code>IN</Code>      			</UnitOfMeasurement>	        	<Length>20</Length>	        	<Width>20</Width>	        	<Height>20</Height>			</Dimensions>      	<PackageWeight>      		<UnitOfMeasurement>      			 <Code>LBS</Code>      		</UnitOfMeasurement>	        <Weight>23</Weight>      	</PackageWeight>      	</Package>  </Shipment></RatingServiceSelectionRequest>

Link to comment
Share on other sites

First, I would definitely not recommend javascript/ajax for this since you must pass that authentication xml with each request. If you posted this with javascript, people would be able to look at that file to figure out the password you use to access this Web Service.Second, you can't use AJAX to send requests to domains other than the domain that served the page.Third, I don't know PHP well enough to help you much. In C# and .NET you'd use an HttpRequest or a WebClient to POST data to another server. Maybe you could post a question in the PHP forum asking how you POST data to another server without using a form.

Link to comment
Share on other sites

Read the Web Serives tutorial and it's realted ones. They descibe a standart syntax for the exact same principal of "send one XML=>Receive another" you're trying to achieve. By using this standart set, you will ease integration with the server, scince tools already exist and clients would know what to expect.For PHP, see the SOAP functions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...