Jump to content

Ocs-server/Gfx4/OCS Client

From KDE Community Wiki

OCSClient is a basic HTTP client with support for http authentication, uploading files and get/post requests. It also automatically handles the correct path to OCS server and xml parsing, returning an associative array.

Requires cURL and php5-curl.


Here is an example GET post with authentication:

$client = new OCSClient(EConfig::$data["ocs"]["host"]);
$client->set_auth_info("test","password");
$check = $client->get("v1/friend/data/example");

Check will contain the resulting array.


Example of POST request with postdata.

$postdata = array(
			"message" => "would you be my friend?"
			);
$client = new OCSClient(EConfig::$data["ocs"]["host"]);
$client->set_auth_info("test","password");
$client->set_post_data($postdata);
$check = $client->post("v1/friend/invite/example ");

Example of POST request with postdata and upload of a file:

$postdata = array(
			"message" => "would you be my friend?"
			);
$client = new OCSClient(EConfig::$data["ocs"]["host"]);
$client->set_auth_info("test","password");
$client->set_upload_file($_FILES['inputScreenshot1']['tmp_name']);
$client->set_post_data($postdata);
$check = $client->post("v1/friend/invite/example ");