VCR\Util\HttpUtil::parseResponse PHP Метод

parseResponse() публичный статический Метод

Returns status, headers and body from a HTTP response string.
public static parseResponse ( string $response ) : array
$response string Response including header and body.
Результат array Status, headers and body as strings.
    public static function parseResponse($response)
    {
        $response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $response);
        list($rawHeader, $rawBody) = explode("\r\n\r\n", $response, 2);
        // Parse headers and status.
        $headers = self::parseRawHeader($rawHeader);
        $status = array_shift($headers);
        return array($status, $headers, $rawBody);
    }

Usage Example

Пример #1
0
 /**
  * Returns a response for specified HTTP request.
  *
  * @param Request $request HTTP Request to send.
  *
  * @return Response Response for specified request.
  */
 public function send(Request $request)
 {
     $ch = curl_init($request->getUrl());
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($ch, CURLOPT_HTTPHEADER, HttpUtil::formatHeadersForCurl($request->getHeaders()));
     if (!is_null($request->getBody())) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getBody());
     }
     curl_setopt_array($ch, $request->getCurlOptions());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FAILONERROR, false);
     curl_setopt($ch, CURLOPT_HEADER, true);
     list($status, $headers, $body) = HttpUtil::parseResponse(curl_exec($ch));
     return new Response(HttpUtil::parseStatus($status), HttpUtil::parseHeaders($headers), $body, curl_getinfo($ch));
 }