Here is an updated example that will work with Liferay 5.2.3
This example uses the Zend API just because it was what I had available at the time, but the concept applies to any Http client API in PHP or any other language for that matter. The main thing to notice here is that the serviceClassName is different, because ServiceBuilder no longer generates the *ServiceJSON.java files.
Also, make sure you add this line to your portal-ext.properties file to allow the json servlet to be accessible from some IP address or hostname:
json.servlet.hosts.allowed=localhost,127.0.0.1
1
2<?php
3require_once ('Zend/Http/Client.php');
4require_once ('Zend/Json.php');
5
6$liferay = new Zend_Http_Client();
7
8$liferay->setUri('http://localhost:8080/tunnel-web/secure/json');
9
10// set parameters to return a list of countries from the Liferay db
11$liferay->setParameterGet(array(
12 'serviceClassName' => 'com.liferay.portal.service.CountryServiceUtil',
13 'serviceMethodName' => 'getCountries'
14));
15
16// set authentication
17$liferay->setAuth('userid', 'password');
18
19// send the request
20$result = $liferay->request("GET");
21
22// get back a json response
23$json = Zend_Json::decode($result->getBody());
24
25// print the json object
26echo $result->getBody();
27
28?>
And if you're having trouble getting it to work, check out SecureFilter.java, JSONServiceAction.java, and JSONServlet.java to figure out what's going on.