I am trying to connect to an api written in php from a java client.
For simplicity of the issue, I reduced the api to the following: (which simply returns the request given to the server)
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
define('DATA_PATH', realpath(dirname(__FILE__).'/data'));
$applications = array(
'APP001' => '28e336ac6c9423d946ba02d19c6a2632', //randomly generated app key for php client
'APP002' => '38e336ac6c9423d946ba02d19c6a2632' // for java app
);
require_once 'models/TodoItem.php';
echo"request";
foreach ($_REQUEST as $result) {
echo $result;
echo "<br>";
}
echo"end";
exit();
I am sending the request as follows: (string param is the string in the code snippet after this)
URL url;
HttpURLConnection connection = null;
try {
url = new URL(APP_URI);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length", "" +
Integer.toString(param.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream (
connection.getOutputStream ());
wr.writeBytes (param);
wr.flush ();
wr.close ();
//Get Response
InputStream is = connection.getInputStream();
// read from input stream
The request string being passed is as follows: (a json object with 2 params, one of which is another json object)
{"app_id":"APP002","enc_request":"{\"username\":\"nikko\",\"action\":\"checkUser\",\"userpass\":\"test1234\",\"controller\":\"todo\"}"}
The reply is as follows, which consist only of the start and end tags I'm manually echoing and no content:
requestend
Why am I not getting any content on the server side?