andy1212 Posted July 25, 2013 Share Posted July 25, 2013 Hey, I'd like to grab xml data by passing get variables through an https ssl secured url and then parse it. What would be the best way to go about doing that and is there a solid tutorial with step by step on how to do that? Thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/ Share on other sites More sharing options...
Solution requinix Posted July 25, 2013 Solution Share Posted July 25, 2013 $url = "http://www.example.com/path/to/page?"; // with the question mark $get = array("key 1" => "value 1", "key 2" => "value 2", "key 3" => "value 3" /* ... */); $xml = new SimpleXMLElement($url . http_build_query($get), 0, true);From there you have a SimpleXMLElement that you can do pretty much anything you want with. What do you want to do? What kind of XML are you getting back? Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442174 Share on other sites More sharing options...
andy1212 Posted July 25, 2013 Author Share Posted July 25, 2013 (edited) its not http:// its https:// and ssl secured so I need to handshake or authenticate with the page before grabbing the xml data and bringing it back to me webpage. The url looks like this,  I have the url setup like this, $xml = ' weight_system="IMPERIAL" shipper_number="000222000" destination_postal_code="'.$data5['zip'].'" service_type="1" '; $xml2 = ' total_pieces="'.$value.'" total_weight="'.$weight.'" '; $token = 'token'; $base_url = 'https://www.shippingco.com/XML/RatingXML.jsp'; $request_url = $base_url . '?' . http_build_query(array(   'shipment' => '<shipment ' . $xml . '><total ' . $xml2 . '/></shipment>',   'token' => $token )); I have an RSA key, SSL cert, CA bundle and password and need to use that information to authenticate with the url to grab the xml data. and xml example   <rating xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.shippingco.com/XML/rating.xsd"> <rate weight="5.0" weight_unit="lb" zone="3" transit_time="1" transit_time_guaranteed="false" estimated_delivery_date="2013-07-26" base_charge="11.05" freight_charge="11.05"residential_address_charge="2.75" net_charge="13.80" fuel_surcharge_rate="15.8" fuel_surcharge="1.75" subtotal_charge="15.55" on_hst_charge="2.02" total_charge="17.57"/> </rating> So how would I go about doing that? Edited July 25, 2013 by andy1212 Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442182 Share on other sites More sharing options...
andy1212 Posted July 25, 2013 Author Share Posted July 25, 2013 ? Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442202 Share on other sites More sharing options...
andy1212 Posted July 26, 2013 Author Share Posted July 26, 2013 ? Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442281 Share on other sites More sharing options...
andy1212 Posted July 26, 2013 Author Share Posted July 26, 2013 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442285 Share on other sites More sharing options...
requinix Posted July 26, 2013 Share Posted July 26, 2013 Nope. What have you discovered in the last 24 hours?  its not http:// its https:// and ssl secured so I need to handshake or authenticate with the page before grabbing the xml data and bringing it back to me webpageIf you want to actually built the TCP/IP packets yourself then sure, go ahead and climb that mountain. But the rest of us don't mind letting PHP and our operating system do that work for us. Or to be more blunt, are you saying file_get_contents($request_url)does not work? Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442332 Share on other sites More sharing options...
andy1212 Posted July 29, 2013 Author Share Posted July 29, 2013 (edited) I tried file_get_contents($request_url) and I don't know if it works or not because when I try echoing out $result, nothing is echoed. When I try var_dump($result) I get bool(false) so how do I know it's working... Shouldn't xml data be echoed? Edited July 29, 2013 by andy1212 Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442570 Share on other sites More sharing options...
andy1212 Posted July 29, 2013 Author Share Posted July 29, 2013 (edited) Nvm you were right, simplexml_load_file($request_url); worked! When echoing out it echoed out the xml!!! Finally I can move on to figure out how to parse it lol thanks so much! Edited July 29, 2013 by andy1212 Quote Link to comment https://forums.phpfreaks.com/topic/280514-trying-to-grab-xml-data-through-a-url/#findComment-1442572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.