Jump to content

Trying to grab xml data through a url


Go to solution Solved by requinix,

Recommended Posts

  • Solution
$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?

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 by andy1212

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 webpage

If 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?

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 by andy1212
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.