public function basicPost($url, $data = NULL) { $token = $this->getToken(); if (!$token) { return false; } // $reqUrl = 'https://' . $this->host . $url; $request = new myRequest(); $request->setMethod(myRequest::METHOD_POST); // if ($data) { $request->setBody(json_encode($data)); } // $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $token]); $response = $request->sendRequest($reqUrl); if ($response->getStatus() == myResponse::STATUS_FORBIDDEN) { // try to regenerate token $request->setHeaders(['Content-type' => 'application/json', 'Authorization' => $this->generateToken()]); // retry request $response = $request->sendRequest($reqUrl); } return $response->getBody(true); }