2.2.4 :: getMarkupFromUrl via CURL

getMarkupFromUrl



Use this function to retrieve the correct markup for the mobile device, by specifying a url that outputs WAPL.


  • devKey - used for authentication and to log usage.

  • url - an absolute url to a static WAPL document or a script that outputs WAPL.

  • headers - the headers of the device you wish to query.



Returns:
Upon success, XML containing header information and markup for the device
Upon failure, error codes WAPL markup

PHP Example


Nb. The example below uses CURL in PHP. The code is for demonstration purposes only and should be modified for use in a production environment.
  1.  <?php
  2.  
  3.  // XML headers and open
  4.  $url = 'http://wapl.info/files/examples/hello_world_1.xml';
  5.  
  6.  $headers = '';
  7.  foreach($_SERVER as $key => $val)
  8.  {
  9.   $headers .= $key.':'.$val.'|';
  10.  }
  11.  
  12.  $postfields = array(
  13.   'devKey' => 'YOUR_DEV_KEY',
  14.   'waplUrl' => $url,
  15.   'headers' => $headers
  16.  );
  17.  
  18.  $c = curl_init();
  19.  curl_setopt($c, CURLOPT_URL, 'http://webservices.wapple.net/getMarkupFromUrl.php');
  20.  curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  21.  curl_setopt($c, CURLOPT_POST, 1);
  22.  curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
  23.  
  24.  $result = curl_exec($c);
  25.  curl_close($c);
  26.  
  27.  $xml = simplexml_load_string($result);
  28.  foreach($xml->header->item as $val)
  29.  {
  30.   header($val);
  31.  }
  32.  echo trim($xml->markup);
  33.  ?>

Parsed XML Response


  1.  <wapple_response>
  2.  <session_id>
  3.  842gsi2c1t16ggcf5pfqjhgnp0
  4.  </session_id>
  5.  <header>
  6.  <item><![CDATA[Cache-Control: no-store, no-cache, max-age=0, s-maxage=0, post-check=0, pre-check=0, public, must-revalidate]]></item>
  7.  
  8.  <item><![CDATA[Pragma: no-cache]]></item>
  9.  <item><![CDATA[Last-Modified: Thu, 25 Sep 2008 16:03:52 GMT]]></item>
  10.  <item><![CDATA[Expires: Thu, 25 Sep 2008 16:03:51 GMT]]></item>
  11.  <item><![CDATA[Content-Type: text/vnd.wap.wml; charset=utf-8]]></item>
  12.  </header>
  13.  <markup>
  14.  <![CDATA[<?xml version="1.0" encoding="utf-8" ?>
  15.  <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
  16.  "http://www.wapforum.org/DTD/wml_1.1.xml">
  17.  <wml>
  18.  <card id="card" title="Wapple Home"><p>
  19.  SOME FAKE WAPL!
  20.  &#160;
  21.  <img src="http://go.wapple.net/sitegraphic/4051_842gsi2c1t16ggcf5pfqjhgnp0_bd0c05cd/bin.jpg" alt="loading." />
  22.  &#160;
  23.  <br />
  24.  </p>
  25.  </card>
  26.  </wml>]]>
  27.  </markup></wapple_response>
Downloadlisting 2.2.4.b

Contents