Hi,
you definitely should not put your request body in the url.
If you have the POST content in the right place (in request body) you
have two alternatives:
1) Use a file validator like <validator
class="file"><argument>post_file</argument></validator>. Then you can
access the raw json string with $rd->getFile('post_file')->getContents()
2) Subclass AgaviWebRequest and do something like this:
public function initialize(AgaviContext $context, array $parameters
= array()) {
parent::initialize($context, $parameters);
$rd = $this->getRequestData();
$jsonData = null;
if (($this->getMethod() == "write" || $this->getMethod() ==
"update") && isset($_SERVER['CONTENT_TYPE'])
&& preg_match('#^application/json(;[^;]+)*?$#', $_SERVER['CONTENT_TYPE'])) {
$jsonStr = "";
if ($this->getMethod() == "update") {
$file = $rd->getFile('put_file'); /* @var $file
AgaviUploadedFile */
$jsonStr = $file->getContents();
}
else {
$jsonStr = file_get_contents('php://input');
}
if (!strlen($jsonStr)) {
throw new Exception('Empty request body');
}
$jsonData = json_decode($jsonStr, true);
}
if ($jsonData) {
$rd->setParameters($jsonData);
}
}
Niklas
20.2.2012 11.00, André Fiedler / ö_konzept Zwickau kirjoitti:
Hi Users :o)
How do I validate suche a POST Request?
Post Data (JSON String):
http://foo.bar/api?%5B%7B%22action%22%3A%22Administration_UserApi%22%2C%22method%22%3A%22createRecord%22%2C%22data%22%3A%5B%7B%22id%22%3A0%2C%22username%22%3A%22l%5Cu00f6schmich%22%2C%22password%22%3A%22ergrege5%22%2C%22first_name%22%3A%22thtrhtrh%22%2C%22last_name%22%3A%22trhtrhtr%22%2C%22email%22%3A%22gtfegge%40gregf.de%22%2C%22birthday%22%3A%22%22%2C%22phone%22%3A%22%22%2C%22mobile_phone%22%3A%22%22%2C%22fax%22%3A%22%22%2C%22department%22%3A%22%22%2C%22title%22%3A%22%22%2C%22business_title%22%3A%22%22%2C%22salutation%22%3A%22Herr%22%2C%22description%22%3A%22%22%2C%22roles%22%3A%5B%7B%22role%22%3A%22editor%22%2C%22name%22%3A%22Mitarbeiter%22%2C%22credentials%22%3A%7B%22app.launch%22%3A%22Anwendung%20starten%22%7D%7D%5D%2C%22last_login%22%3A%22%22%2C%22is_locked%22%3Afalse%7D%5D%2C%22type%22%3A%22rpc%22%2C%22tid%22%3A5%7D%2C%7B%22action%22%3A%22Administration_UserApi%22%2C%22method%22%3A%22getRecords%22%2C%22data%22%3A%5B%7B%22page%22%3A1%2C%22start%22%3A0%2C%22limit%22%3A25%7D%5D%2C%22type%22%3A%22rpc%22%2C%22tid%22%3A6%7D%5D=
_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.agavi.org/mailman/listinfo/users