Jump to content
jakester

Connecting and Posting to UPS XML Server

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>

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...