+ if ($this->sendAsJson) {
+ //application/json
+ if ($body !== null) {
+ throw new \Exception('body already defined');
+ }
+ $this->req->setHeader('Content-Type: application/json');
+ $data = [];
+ if ($this->action !== null) {
+ $data['action'] = $this->action;
+ }
+ if ($this->url !== null) {
+ $data['url'] = $this->url;
+ }
+ if ($this->type !== null) {
+ $data['type'] = array('h-' . $this->type);
+ }
+ if (count($this->properties)) {
+ $data['properties'] = $this->properties;
+ }
+ $body = json_encode($data);
+ } else {
+ //form-encoded
+ if ($this->type !== null) {
+ $this->req->addPostParameter('h', $this->type);
+ }
+ if ($this->action !== null) {
+ $this->req->addPostParameter('action', $this->action);
+ }
+ if ($this->url !== null) {
+ $this->req->addPostParameter('url', $this->url);
+ }
+ foreach ($this->properties as $propkey => $propval) {
+ if (isset($propval['html'])) {
+ //workaround for content[html]
+ $propkey = $propkey . '[html]';
+ $propval = $propval['html'];
+ } else if (count($propval) == 1) {
+ $propval = reset($propval);
+ }
+ $this->req->addPostParameter($propkey, $propval);
+ }
+ }
+