public function doPost() { error_log("GadgetDataServlet received POST request."); $requestParam = isset($_POST['request']) ? $_POST['request'] : ''; $token = isset($_POST['st']) ? $_POST['st'] : ''; // detect if magic quotes are on, and if so strip them from the request if (get_magic_quotes_gpc()) { $requestParam = stripslashes($requestParam); } $request = json_decode($requestParam, true); error_log("Request was:\n" . implode(",", $request)); if ($request == $requestParam) { // oddly enough if the json_decode function can't parse the code, // it just returns the original string (instead of something usefull like 'null' or false :)) error_log("Invalid request JSON"); throw new Exception("Invalid request JSON"); } try { $response = new DataResponse($this->createResponse($requestParam, $token)); } catch (Exception $e) { error_log("ERROR " . $e); $response = new DataResponse(false, BAD_REQUEST); } // // Build assoc arrays for JSON encoding // foreach ($response->getResponses() as $arryResponses ){ // foreach ($arryResponses as $aRespItem ){ // $assocJsonResponses[]=$aRespItem; // } // } error_log("There were " . sizeof($response->getResponses())) . " fields in the response."; $arryResponses['responses'] = $response->getResponses(); $reponse1 = json_encode($arryResponses); error_log("Response was:\n " . $reponse1); echo $reponse1; }