src/Request.php
public function send($method, $url, $parameters = [], $headers = [])
    {
        // Reset any old responses
        $this->lastResponse = [];

        // Sometimes a stringified JSON object is passed
        if (is_array($parameters) || is_object($parameters)) {
            $parameters = http_build_query($parameters);
        }

        $mergedHeaders = [];
        foreach ($headers as $key => $val) {
            $mergedHeaders[] = "$key: $val";
        }

        $options = [
            CURLOPT_CAINFO => __DIR__ . '/cacert.pem',
            CURLOPT_ENCODING => '',
            CURLOPT_HEADER => true,
            CURLOPT_HTTPHEADER => $mergedHeaders,
            CURLOPT_RETURNTRANSFER => true,
        ];

        $url = rtrim($url, '/');
        $method = strtoupper($method);

        switch ($method) {
            case 'DELETE': // No break
            case 'PUT':
                $options[CURLOPT_CUSTOMREQUEST] = $method;
                $options[CURLOPT_POSTFIELDS] = $parameters;

                break;
            case 'POST':
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = $parameters;

                break;
            default:
                $options[CURLOPT_CUSTOMREQUEST] = $method;

                if ($parameters) {
                    $url .= '/?' . $parameters;
                }

                break;
        }

        $options[CURLOPT_URL] = $url;

        $ch = curl_init();
        curl_setopt_array($ch, $options);

        $response = curl_exec($ch);

        if (curl_error($ch)) {
            throw new SpotifyWebAPIException('cURL transport error: ' . curl_errno($ch) . ' ' .  curl_error($ch));
        }

        list($headers, $body) = explode("\r\n\r\n", $response, 2);

        // Skip the first set of headers for proxied requests
        if (preg_match('/^HTTP\/1\.\d 200 Connection established$/', $headers) === 1) {
            list($headers, $body) = explode("\r\n\r\n", $body, 2);
        }

        $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headers = $this->parseHeaders($headers);

        $this->lastResponse = [
            'headers' => $headers,
            'status' => $status,
            'url' => $url,
        ];

        // Run this here since we might throw
        $body = $this->parseBody($body, $status);

        curl_close($ch);

        return $this->lastResponse;
    }
public function send($method, $url, $parameters = [], $headers = [])
    {
        // Reset any old responses
        $this->lastResponse = [];

        // Sometimes a stringified JSON object is passed
        if (is_array($parameters) || is_object($parameters)) {
            $parameters = http_build_query($parameters);
        }

        $mergedHeaders = [];
        foreach ($headers as $key => $val) {
            $mergedHeaders[] = "$key: $val";
        }

        $options = [
            CURLOPT_CAINFO => __DIR__ . '/cacert.pem',
            CURLOPT_ENCODING => '',
            CURLOPT_HEADER => true,
            CURLOPT_HTTPHEADER => $mergedHeaders,
            CURLOPT_RETURNTRANSFER => true,
        ];

        $url = rtrim($url, '/');
        $method = strtoupper($method);

        switch ($method) {
            case 'DELETE': // No break
            case 'PUT':
                $options[CURLOPT_CUSTOMREQUEST] = $method;
                $options[CURLOPT_POSTFIELDS] = $parameters;

                break;
            case 'POST':
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = $parameters;

                break;
            default:
                $options[CURLOPT_CUSTOMREQUEST] = $method;

                if ($parameters) {
                    $url .= '/?' . $parameters;
                }

                break;
        }

        $options[CURLOPT_URL] = $url;

        $ch = curl_init();
        curl_setopt_array($ch, $options);

        $response = curl_exec($ch);

        if (curl_error($ch)) {
            throw new SpotifyWebAPIException('cURL transport error: ' . curl_errno($ch) . ' ' .  curl_error($ch));
        }

        list($headers, $body) = explode("\r\n\r\n", $response, 2);

        // Skip the first set of headers for proxied requests
        if (preg_match('/^HTTP\/1\.\d 200 Connection established$/', $headers) === 1) {
            list($headers, $body) = explode("\r\n\r\n", $body, 2);
        }

        $status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $headers = $this->parseHeaders($headers);

        $this->lastResponse = [
            'headers' => $headers,
            'status' => $status,
            'url' => $url,
        ];

        // Run this here since we might throw
        $body = $this->parseBody($body, $status);

        curl_close($ch);

        return $this->lastResponse;
    }
public function send ( $ method , $ url , $ parameters = [ ] , $ headers = [ ] ) { // Reset any old responses $ this -> lastResponse = [ ] ; // Sometimes a stringified JSON object is passed if ( is_array ( $ parameters ) || is_object ( $ parameters ) ) { $ parameters = http_build_query ( $ parameters ) ; } $ mergedHeaders = [ ] ; foreach ( $ headers as $ key => $ val ) { $ mergedHeaders [ ] = "$key: $val" ; } $ options = [ CURLOPT_CAINFO => __DIR__ . '/cacert.pem' , CURLOPT_ENCODING => '' , CURLOPT_HEADER => true , CURLOPT_HTTPHEADER => $ mergedHeaders , CURLOPT_RETURNTRANSFER => true , ] ; $ url = rtrim ( $ url , '/' ) ; $ method = strtoupper ( $ method ) ; switch ( $ method ) { case 'DELETE' : // No break case 'PUT' : $ options [ CURLOPT_CUSTOMREQUEST ] = $ method ; $ options [ CURLOPT_POSTFIELDS ] = $ parameters ; break ; case 'POST' : $ options [ CURLOPT_POST ] = true ; $ options [ CURLOPT_POSTFIELDS ] = $ parameters ; break ; default : $ options [ CURLOPT_CUSTOMREQUEST ] = $ method ; if ( $ parameters ) { $ url .= '/?' . $ parameters ; } break ; } $ options [ CURLOPT_URL ] = $ url ; $ ch = curl_init ( ) ; curl_setopt_array ( $ ch , $ options ) ; $ response = curl_exec ( $ ch ) ; if ( curl_error ( $ ch ) ) { throw new SpotifyWebAPIException ( 'cURL transport error: ' . curl_errno ( $ ch ) . ' ' . curl_error ( $ ch ) ) ; } list ( $ headers , $ body ) = explode ( "\r\n\r\n" , $ response , 2 ) ; // Skip the first set of headers for proxied requests if ( preg_match ( '/^HTTP\/1\.\d 200 Connection established$/' , $ headers ) === 1 ) { list ( $ headers , $ body ) = explode ( "\r\n\r\n" , $ body , 2 ) ; } $ status = ( int ) curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; $ headers = $ this -> parseHeaders ( $ headers ) ; $ this -> lastResponse = [ 'headers' => $ headers , 'status' => $ status , 'url' => $ url , ] ; // Run this here since we might throw $ body = $ this -> parseBody ( $ body , $ status ) ; curl_close ( $ ch ) ; return $ this -> lastResponse ; }
Make a request to Spotify.
You'll probably want to use one of the convenience methods instead.

@param string $method The HTTP method to use.
@param string $url The URL to request.
@param array $parameters Optional. Query string parameters or HTTP body, depending on $method.
@param array $headers Optional. HTTP headers.

@throws SpotifyWebAPIException
@throws SpotifyWebAPIAuthException

@return array Response data.
- array|object body The response body. Type is controlled by `Request::setReturnType()`.
- array headers Response headers.
- int status HTTP status code.
- string url The requested URL.
Make a request to Spotify . You ll probably want to use one of the convenience methods instead .