Blogs
Liferay offers a wide variety of different remote API's.
A very useful one is JSON. It's useful because most languages have JSON processing functions. So the only dependencies are those and HTTP request handling functions.
Here is a complete example of adding a Country from a PHP script:
<?php
#
# This example uses HTTP_Request package located found here:
#
# http://pear.php.net/package/HTTP_Request
#
# Tested with:
# Liferay Portal - revision 13652
# HTTP_Request - version 1.4.1
#
require_once("HTTP/Request.php");
#
# URL to the tunnle-web JSON API.
#
$a = &new HTTP_Request('http://localhost:8080/tunnel-web/secure/json');
#
# Use POST in 99% of cases, so that encoding of passed data is handled properly.
#
$a->setMethod("POST");
#
# Specify the authentication credientials.
#
$a->setBasicAuth("2","test");
#
# Specify the service class.
#
$a->addPostData("serviceClassName", "com.liferay.portal.service.http.CountryServiceJSON");
#
# Specify the service method.
#
$a->addPostData("serviceMethodName", "addCountry");
#
# List the method parameters.
#
$a->addPostData("serviceParameters", "name,a2,a3,number,idd,active");
#
# Give the values to use in the method.
#
$a->addPostData("name", "AAAAAA");
$a->addPostData("a2", "AA");
$a->addPostData("a3", "AA");
$a->addPostData("number", "1000000");
$a->addPostData("idd", "1000000");
$a->addPostData("active", "true");
#
# Send the request.
#
$a->sendRequest();
echo $a->getResponseBody();
#
# If the country does not exist, this will print:
#
# {"active":true,"a2":"AA","a3":"AA","idd":"1000000","countryId":10904,"name":"AAAAAA","number":"1000000"}
#
#
# The above indicates success. Notice that "countryId" is included in the result.
#
?>

