Let's also look at how to use RESTClient class for a POST request with the library service.
<?php require "RESTClient.php"; $data = <<<XML <books> <book><name>Book7</name><author>Auth7</author><isbn>ISBN0007</isbn></book> <book><name>Book8</name><author>Auth8</author><isbn>ISBN0008</isbn></book> </books> XML; $client = new RESTClient(); $client->post("http://localhost/rest/09/library.php/book", $data, "text/xml"); ?>
As in the case of the sample used to GET data, the POST sample is very simple. First require the PHP file with the class implementation.
require "RESTClient.php";
Then we define the data that we want to be posted to the service.
$data = <<<XML <books> <book><name>Book7</name><author>Auth7</author><isbn>ISBN0007</isbn></book> <book><name>Book8</name><author>Auth8</author><isbn>ISBN0008</isbn></book> </books> XML;
Next, create the RESTClient class instance.
$client = new RESTClient();
And post the data to the service.
$client->post("http://localhost/rest/09/library.php/book", $data, "text/xml");
Note that we have used the third parameter with the value text/xml
to indicate that we are posting XML data to the service.