Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.
[Info]
REST
rest_handle.php
<?php
function handleREST($server,$get) {
$url = (array_key_exists('PATH_INFO',$server) ? $server['PATH_INFO'] : '/');
$method = $server['REQUEST_METHOD'];
parse_str(file_get_contents('php://input'),$contentargs);
$arguments = array_merge($get,$contentargs);
$accept = array_key_exists('HTTP_ACCEPT',$server) ? $server['HTTP_ACCEPT'] : '*/*';
$ret = new StdClass;
$ret->url = $url;
$ret->method = $method;
$ret->arguments = $arguments;
$ret->accept = $accept;
return $ret;
}
?>
server.php
<?php
include('rest_handle.php');
$rest = handleREST($_SERVER,$_GET);
print_r($rest);
?>
client.php for GET
<?php
header('content-type: text/plain');
$result = file_get_contents('http://solo.wst.univie.ac.at/interop/studi_server_rest.php/bla/blo?a=b&b=c');
print_r($result);
?>
client.php for POST, PUT
<?php
$data = http_build_query(
array(
'var1' => 'some content',
'var2' => 'doh',
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' =>
"Content-type: application/x-www-form-urlencoded\r\n" .
"accept: application/json\r\n"
,
'content' => $data
)
);
header('content-type: text/plain');
$context = stream_context_create($opts);
$result = file_get_contents('http://solo.wst.univie.ac.at/interop/studi_server_rest.php/bla/blo',false,$context);
print_r($result);
?>
client.php for DELETE
<?php
$opts = array('http' =>
array(
'method' => 'POST',
'header' =>
"Content-type: application/x-www-form-urlencoded\r\n" .
"accept: application/json\r\n"
)
);
header('content-type: text/plain');
$context = stream_context_create($opts);
$result = file_get_contents('http://solo.wst.univie.ac.at/interop/studi_server_rest.php/bla/blo',false,$context);
print_r($result);
?>
Letzte Änderung: 03.05.2017, 23:44 | 131 Worte