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.

REST Example

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);
?>
 
post.php 
 
<?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);
?>
Letzte Änderung: 23.04.2015, 14:31 | 80 Worte