public function execute(Request $request) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request->getUrl()); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); $username = $request->getUsername(); $password = $request->getPassword(); if ($username && $password) { curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password); } switch ($request->getMethod()) { case self::POST: case self::PUT: curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request->getParameters())); break; case self::DELETE: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; case self::GET: default: break; } $result = curl_exec($ch); if (!$result) { $errorNumber = curl_errno($ch); $error = curl_error($ch); curl_close($ch); throw new \Exception($errorNumer . ': ' . $error); } curl_close($ch); return $request->getResponseTransformerImpl()->transform($result); }