-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.php
More file actions
71 lines (58 loc) · 1.98 KB
/
proxy.php
File metadata and controls
71 lines (58 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// Peter Dol: gebaseerd op http://blog.michaelkidd.com/2007/10/php-ajax-proxy.html
// Allowed hostname
define ('HOSTNAME', 'https://ideas.science.uu.nl');
//returns the headers as an array
function getHeaders()
{
$headers = array();
foreach ($_SERVER as $k => $v)
{
if (substr($k, 0, 5) == "HTTP_")
{
$k = str_replace('_', ' ', substr($k, 5));
$k = str_replace(' ', '-', ucwords(strtolower($k)));
$headers[$k] = $v;
}
}
return $headers;
}
// Get the REST call path from the AJAX application
$path = $_REQUEST['path'];
$url = HOSTNAME.$path;
// Open the Curl session
$session = curl_init($url);
// If it's a POST, put the POST data in the body
if ($_POST['path']) {
$postvars = '';
while ($element = current($_POST)) {
$postvars .= key($_POST).'='.$element.'&';
next($_POST);
}
$postvars = substr($postvars, 0, -1); // removing trailing &
$postvars = str_replace('xml_version', 'xml version', $postvars); // fix xml declaration bug?
$postvars = stripslashes($postvars);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
else {
//If it's a post, but not a form post (like a SOAP request)
if ($_SERVER['REQUEST_METHOD']==='POST') {
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $HTTP_RAW_POST_DATA);
$headers = getHeaders();
$header_array = Array( "Content-Type: text/xml", "SOAPAction: " . $headers['SOAPAction']);
curl_setopt ($session, CURLOPT_HTTPHEADER, $header_array);
curl_setopt ($session, CURLOPT_CUSTOMREQUEST, "POST");
}
}
// Don't return HTTP headers. Do return the contents of the call
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// Make the call
$response = curl_exec($session);
// The web service returns application/json. Set the Content-Type appropriately
header("Content-Type: application/json");
echo $response;
curl_close($session);
?>