Skip to content

Instantly share code, notes, and snippets.

@zackchandler
Created October 13, 2009 21:36
Show Gist options
  • Select an option

  • Save zackchandler/209590 to your computer and use it in GitHub Desktop.

Select an option

Save zackchandler/209590 to your computer and use it in GitHub Desktop.
<?php
// Loosely based on the Jason Levitt PHP Proxy example for Yahoo! Web services.
define ('HOSTNAME', 'https://myapp.servicesidekick.com/');
$path = ($_POST['api_path']) ? $_POST['api_path'] : $_GET['api_path'];
// Build url and add any parameters
$url = HOSTNAME.$path.'?';
while ($element = current($_GET)) {
$url .= key($_GET).'='.$element.'&';
next($_GET);
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'abc123:abc123');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $HTTP_RAW_POST_DATA);
}
$xml = @curl_exec($ch);
curl_close($ch);
header("Content-Type: text/xml");
echo $xml;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment