public function send(Aplazame_Sdk_Http_RequestInterface $request) { $rawHeaders = array(); foreach ($request->getHeaders() as $header => $value) { $rawHeaders[] = sprintf('%s:%s', $header, implode(', ', $value)); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request->getUri()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod()); curl_setopt($ch, CURLOPT_HTTPHEADER, $rawHeaders); $body = $request->getBody(); if (!empty($body)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $body); } $responseBody = curl_exec($ch); if (false === $responseBody) { $message = curl_error($ch); $code = curl_errno($ch); curl_close($ch); throw new RuntimeException($message, $code); } $response = new Aplazame_Sdk_Http_Response(curl_getinfo($ch, CURLINFO_HTTP_CODE), $responseBody); curl_close($ch); return $response; }
public function send(Aplazame_Sdk_Http_RequestInterface $request) { $rawHeaders = array(); foreach ($request->getHeaders() as $header => $value) { $rawHeaders[] = sprintf('%s:%s', $header, implode(', ', $value)); } $client = new Zend_Http_Client($request->getUri()); $client->setHeaders($rawHeaders); $client->setMethod($request->getMethod()); $body = $request->getBody(); if (!empty($body)) { $client->setRawData($body); } try { $zendResponse = $client->request(); } catch (Exception $e) { throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } $responseBody = $zendResponse->getBody(); $response = new Aplazame_Sdk_Http_Response($zendResponse->getStatus(), $responseBody); return $response; }