WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2007, 12:32 AM
getmea getmea is offline
WebProWorld Pro
 

Join Date: Aug 2006
Location: Cary, Illinois
Posts: 153
getmea RepRank 0
Default HTTP Post of an XML document - Help!

Has anyone coded the UPS Quantum XML code for your site? This api accepts a XML document request with source/destination zip codes and weight. It then sends back a response XML with the shipping cost.

Problem is you need to "post an XML document to their HTTPS site". I have already coded a PHP file which creates the XML request.

But how do I post the document to their site?

How do I parse the XML response back?

I searched but found very few examples I can code from.
__________________
Skateboards and iPods...what a combination!
http://www.getmea-skateboard.com
Reply With Quote
  #2 (permalink)  
Old 04-23-2007, 10:21 AM
speed speed is offline
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Cornwall, UK
Posts: 823
speed RepRank 1
Default

Have a look at cURL http://uk2.php.net/curl it will easily allow you to post to and read data from an address. There's examples on that page.

The page contents returned from curl_exec will be the XML document (assuming no errors), this will just be one big string.

Depending on the document you can either extract the result with a regular expression or an XML parser.

Look at xml_parser_create and its related functions or PEAR if you need a XML parser.
__________________
TOLRA Micro Systems Limited US & UK Web Hosting with Continuous Data Protection
Web Directory : Web Directory Script
Reply With Quote
  #3 (permalink)  
Old 04-23-2007, 02:10 PM
getmea getmea is offline
WebProWorld Pro
 

Join Date: Aug 2006
Location: Cary, Illinois
Posts: 153
getmea RepRank 0
Default

Thanks, Speed...I found a functional curl example for posting to a credit card authorization site. All I'd have to do is to make sure to post the xml string as opposed to the example's edi string. Seems easy enough...thanks again.
__________________
Skateboards and iPods...what a combination!
http://www.getmea-skateboard.com
Reply With Quote
  #4 (permalink)  
Old 04-30-2007, 07:30 PM
getmea getmea is offline
WebProWorld Pro
 

Join Date: Aug 2006
Location: Cary, Illinois
Posts: 153
getmea RepRank 0
Default

Just in case someone needs it, I got the code to work. The following is the "guts"...

$url is the full url you need to call
$xmlrequest is the full formatted XML string the receiver needs
...
build your XML request string
...
$ch = curl_init(); // initialize
curl_setopt($ch, CURLOPT_URL, $url); // set the url
curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
curl_setopt($ch, CURLOPT_POST, 1); // not sure what this one does
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xmlrequest"); // use HTTP POST to send XML data
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
### curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. ###
$xmlresponse = curl_exec($ch); //execute post and get results
curl_close ($ch); //close the curl interface
...
process your XML response
...
__________________
Skateboards and iPods...what a combination!
http://www.getmea-skateboard.com
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: document, help, http, post, xml



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Search Engine Friendly URLs by vBSEO 3.0.0