load( 'config' ); $serverPort = 80; $serverProtocol = 'http'; $serverHost = $config->get('page/server'); $serverPath = $config->get('page/docroot') . $config->get('page/service/rest'); $captchaUrl = $config->get('page/server'); $captchaPath = $config->get('page/docroot') . '/captcha.php'; // display captcha picture if( isset( $_GET['captcha'] ) ) { header( 'Content-type: image/png' ); $http = array( 'method' => 'GET', ); $context = stream_context_create( array( 'http' => $http ) ); $url = $_GET['url'] .'?WBS=' . $_GET['WBS']; echo file_get_contents( $url, false, $context ); exit; } // form default parameter $methodChecked = array('GET' => '', 'POST' => '', 'PUT' => '', 'DELETE' => ''); $req = array( 'serverProtocol'=> $serverProtocol, 'serverHost' => $serverHost, 'serverPath' => $serverPath, 'serverPort' => $serverPort, 'captchaHost' => $captchaUrl, 'captchaPath' => $captchaPath, 'nickname' => 'gerd', 'password' => 'gerd123', 'method' => 'GET', 'path' => '/', 'body' => ' ', 'cookies' => '', 'headers' => << $v ) { $req[$k] = stripslashes( $v ); } } } // start client include_once dirname(__FILE__) . '/RestClient.php'; $client = new RestClient($req['serverHost'], $req['serverPort']); $client->setCookie('REST-Client-Message', 'How cool is that?'); $req['headers'] = 'Authorization: Basic ' . base64_encode($req['nickname'] . ':' . $req['password']) . "\n" . $req['headers']; $auth = true; $headers = array(); foreach (explode("\n", $req['headers']) as $hdr) { list($key, $value) = explode(': ', $hdr, 2); if ($key == 'Authorization') { if ($auth) { $headers[] = $hdr; $client->setHeader($key, $value); $auth = false; } continue; } $headers[] = $hdr; $client->setHeader($key, $value); } $req['headers'] = implode("\n", $headers); $methodChecked[$req['method']] = 'checked="checked"'; if (!empty($req['cookies'])) { $cookies = $client->getCookies(); $tmp = explode( "\n", $req['cookies'] ); foreach( $tmp as $c ) { $c = trim( $c ); if( empty( $c ) ) { continue; } list( $key, $value ) = explode('=', $c); $cookies[$key] = $value; } foreach ($cookies as $cookieKey => $cookieValue) { $client->setCookie( $cookieKey, $cookieValue ); } } $path = $req['serverPath'] . $req['path']; switch( $req['method'] ) { case 'GET': $client->get($path); break; case 'PUT': $client->put($path, $req['body']); break; case 'POST': $client->post($path, $req['body']); break; case 'DELETE': $client->delete($path); break; } $state = $client->getResponseState(); $header = $client->getResponseHeader(); $body = $client->getResponseBody(); $reqHeader = $client->getRequestHeader(); $cookies = $client->getCookies(); $tmp = array(); foreach ($cookies as $key => $value) { array_push( $tmp, $key . '=' . $value ); } $req['cookies'] = implode("\n", $tmp); $sid = '?WBS=' . $cookies['WBS']; $captchaUrl = 'url=http://' . $req['captchaHost'] . $req['captchaPath']; echo '' . "\n"; ?> REST Client Server: protocol://server:port ://: Path: Auth data: Nickname Password >GET >PUT >POST >DELETE Path: Cookies: Header: Body: Response Header: Body:
Server: protocol://server:port ://: Path:
Auth data: Nickname Password