Prepare the curl request

@param string $apiCall the API call function
@param array $payload Parameters
@return array
185998
public function request($method, $apiCall, $payload = [])
    {
        $url = rtrim($this->baseUrl . $apiCall, '/?');
        $curl = $this->prepareCurl();
        $browser = new Browser($curl);
        $headers = [
            "Authorization" => "Bearer ".$this->token,
            "Content-type"  => "application/json"
        ];
        $response = $browser->call($url, $method, $headers, json_encode($payload));

        return $response->getContent();
    }
1152870
function parseRequest( $payload )
    {
        $request = new ggJSONRPCRequest();
        if ( $request->decodeStream( $payload ) )
        {
            $this->Id = $request->id();
            return $request;
        }
        else
        {
            return false;
        }
    }
1271547
public function fill($payload)
    {
        $payload = $this->determineTypeAndMessage($payload);
        $payload = $this->fillBlanks($payload);
        return $payload;
    }
499432
protected function preparePayload($id, $payload)
    {
        return json_encode(array_merge(json_decode($payload, true), [
            'id' => $id,
            'attempts' => 0,
            'retry_of' => $this->id,
        ]));
    }
374614
protected static function _httpRequest( $method = self::GET, $url, $payload = array(), $curlOptions = array() )
    {
        if ( !static::contains( $method ) )
        {
            throw new \InvalidArgumentException( 'Invalid method "' . $method . '" specified.' );
        }

        //	Reset!
        static::$_lastResponseHeaders = static::$_lastHttpCode = static::$_error = static::$_info = $_tmpFile = null;

        //	Build a curl request...
        $_curl = curl_init( $url );

        //	Default CURL options for this method
        $_curlOptions = array(
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => true,
            CURLINFO_HEADER_OUT    => true,
            CURLOPT_SSL_VERIFYPEER => false,
        );

        //	Merge in the global options if any
        if ( !empty( static::$_curlOptions ) )
        {
            $curlOptions = array_merge(
                $curlOptions,
                static::$_curlOptions
            );
        }

        //	Add/override user options
        if ( !empty( $curlOptions ) )
        {
            foreach ( $curlOptions as $_key => $_value )
            {
                $_curlOptions[$_key] = $_value;
            }
        }

        if ( null !== static::$_userName || null !== static::$_password )
        {
            $_curlOptions[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
            $_curlOptions[CURLOPT_USERPWD] = static::$_userName . ':' . static::$_password;
        }

        switch ( $method )
        {
            case static::GET:
                //	Do nothing, like the goggles...
                break;

            case static::PUT:
                if (static::$putAsFile)
                {
                    $_payload = json_encode(!empty($payload) ? $payload : []);

                    $_tmpFile = tmpfile();
                    fwrite($_tmpFile, $_payload);
                    rewind($_tmpFile);

                    $_curlOptions[CURLOPT_PUT] = true;
                    $_curlOptions[CURLOPT_INFILE] = $_tmpFile;
                    $_curlOptions[CURLOPT_INFILESIZE] = mb_strlen($_payload);
                }
                else
                {
                    $_curlOptions[CURLOPT_CUSTOMREQUEST] = static::PUT;
                    $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                }
                break;

            case static::POST:
                $_curlOptions[CURLOPT_POST] = true;
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                break;

            case static::HEAD:
                $_curlOptions[CURLOPT_NOBODY] = true;
                break;

            case static::PATCH:
                $_curlOptions[CURLOPT_CUSTOMREQUEST] = static::PATCH;
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
                break;

            case static::MERGE:
            case static::DELETE:
                /** Merge && Delete have payloads, but they and Options/Copy need CURLOPT_CUSTOMREQUEST set so just fall through... */
                $_curlOptions[CURLOPT_POSTFIELDS] = $payload;
            //  intentional drop through...
            case static::OPTIONS:
            case static::COPY:
                $_curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
                break;
        }

        if ( null !== static::$_hostPort && !isset( $_curlOptions[CURLOPT_PORT] ) )
        {
            $_curlOptions[CURLOPT_PORT] = static::$_hostPort;
        }

        //	Set our collected options
        curl_setopt_array( $_curl, $_curlOptions );

        //	Make the call!
        $_result = curl_exec( $_curl );

        static::$_info = curl_getinfo( $_curl );
        static::$_lastHttpCode = Option::get( static::$_info, 'http_code' );
        static::$_responseHeaders = curl_getinfo( $_curl, CURLINFO_HEADER_OUT );
        static::$_responseHeadersSize = curl_getinfo( $_curl, CURLINFO_HEADER_SIZE );

        if ( static::$_debug )
        {
            //	@todo Add debug output
        }

        if ( false === $_result )
        {
            static::$_error = array(
                'code'    => curl_errno( $_curl ),
                'message' => curl_error( $_curl ),
            );
        }
        elseif ( true === $_result )
        {
            //	Worked, but no data...
            $_result = null;
        }
        else
        {
            //      Split up the body and headers if requested
            if ( $_curlOptions[CURLOPT_HEADER] )
            {
                if ( false === strpos( $_result, "\r\n\r\n" ) || empty( static::$_responseHeadersSize ) )
                {
                    $_headers = $_result;
                    $_body = null;
                }
                else
                {
                    $_headers = substr( $_result, 0, static::$_responseHeadersSize );
                    $_body = substr( $_result, static::$_responseHeadersSize );
                }

                if ( $_headers )
                {
                    static::$_lastResponseHeaders = array();
                    $_raw = explode( "\r\n", $_headers );

                    if ( !empty( $_raw ) )
                    {
                        $_first = true;

                        foreach ( $_raw as $_line )
                        {
                            //	Skip the first line (HTTP/1.x response)
                            if ( $_first || preg_match( '/^HTTP\/[0-9\.]+ [0-9]+/', $_line ) )
                            {
                                $_first = false;
                                continue;
                            }

                            $_parts = explode( ':', $_line, 2 );

                            if ( !empty( $_parts ) )
                            {
                                static::$_lastResponseHeaders[trim( $_parts[0] )] = count( $_parts ) > 1 ? trim( $_parts[1] ) : null;
                            }
                        }
                    }
                }

                $_result = $_body;
            }

            //	Attempt to auto-decode inbound JSON
            if ( !empty( $_result ) && false !== stripos( Option::get( static::$_info, 'content_type' ), 'application/json', 0 ) )
            {
                try
                {
                    if ( false !== ( $_json = @json_decode( $_result, static::$_decodeToArray ) ) )
                    {
                        $_result = $_json;
                    }
                }
                catch ( \Exception $_ex )
                {
                    //	Ignored
                    Log::debug( 'Exception decoding result: ' . $_ex->getMessage() );
                }
            }

            //	Don't confuse error with empty data...
            if ( false === $_result )
            {
                $_result = null;
            }
        }

        @curl_close( $_curl );

        //	Close temp file if any
        if ( null !== $_tmpFile )
        {
            @fclose( $_tmpFile );
        }

        return $_result;
    }
689850
public function get(string $url, ?array $payload = null): TransportClientResponse {
        return $this->sendRequest($url . static::QUESTION_MARK . http_build_query($payload), array());
    }
299397
protected function push($url, array $payload, array $headers)
    {
        $request = [
            'headers' => array_merge(
                ['Content-Type' => 'application/json'],
                $headers
            ),
            'json'       => $payload,
            'exceptions' => false,
        ];

        $this->request('put', $url, $request);
    }
211065
public function performContentApiRequest($endpoint, $payload)
    {
        $this->setupRequest($payload);
        $this->apiEndpoint = $endpoint;

        return $this->doDropboxApiContentRequest();
    }
868946
protected function executeRequest(array $httpHeaders, $requestUrl, $httpMethod, $payload)
    {
        $result = [];

        $ch = curl_init($requestUrl);
        curl_setopt_array($ch, [
            CURLOPT_HTTPHEADER => $httpHeaders,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => 0,
        ]);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);

        // Only send payload data for methods that need it.
        if ($payload instanceof Payload) {
            // Send payload data as a JSON string
            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload->getPayloadJSON());
        }

        // Set response data
        $result['response'] = curl_exec($ch);
        // Set response code
        $result['http_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        // Check if any related Curl error occurred.
        if (curl_error($ch)) {
            throw new RequestException(curl_error($ch));
        }

        // Close the session
        curl_close($ch);

        return $result;
    }
1356439
private static function getJsonPayload($payload)
    {
        $payload = json_decode(base64_decode($payload), true);
        if (! $payload || self::isInvalidPayload($payload)) {
            throw new Exceptions\DecryptionException('The payload is invalid.');
        }

        return $payload;
    }
1208961
private function queryPayload($payload, $path = null)
    {
        if(is_null($path)) return $payload;

        if(array_key_exists($path, $payload)) {
            return $payload[$path];
        }

        $dotData = Arr::dot($payload);
        if(array_key_exists($path, $dotData)) {
            return $dotData[$path];
        }

        return null;
    }
853393
protected static function prepareRequest($url, $parameters = [], $headers = [])
    {
        $request = curl_init();

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

        curl_setopt($request, CURLOPT_URL, $url);
        curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($request, CURLINFO_HEADER_OUT, true);
        curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true);

        return $request;
    }
820529
public function serialize($payload)
    {
        $serialized = '';
        foreach ($payload as $line) {
            $serialized .= '"' . implode('","', $line) . '"' . "\n";
        }
        return $serialized;
    }
1057253
protected function prepareCurl()
    {
        $this->curl = curl_init();
        $this->complete = Complete::factory(function() {
            if ($this->curl) {
                curl_close($this->curl);
            }
            $this->curl     = null;
            $this->complete = null;
        });

        foreach(self::$curlOptions as $option => $value) {
            curl_setopt($this->curl, $option, $value);
        }
        if ($this->method === HttpMethods::POST) {
            curl_setopt($this->curl, CURLOPT_POST, true);
        }
        if (!empty($this->auth)) {
            curl_setopt($this->curl, CURLOPT_USERPWD, sprintf(
                "%s:%s",
                $this->auth["user"],
                $this->auth["pass"]
            ));
        }
    }
799366
public function parse(string $payload): ResultSpec
    {
        $data = @json_decode($payload, true);

        if (!is_array($data)) {
            throw new BaseClientException('Parse error', JsonRpcException::PARSE_ERROR);
        }

        $units = [];

        if ($this->isSingleResponse($data)) {
            $units[] = $this->decodeResult($data);
            return new ResultSpec($units, true);
        }

        /** @var array $data */
        foreach ($data as $response) {
            $units[] = $this->decodeResult($response);
        }

        return new ResultSpec($units, false);
    }
585549
protected function sendRequest($endpoint, $httpMethod, Payload $payload = null)
    {
        return $this->requestHandler->sendRequest($endpoint, $httpMethod, $payload);
    }
351493
protected function authCurl($url, $payload, $header = false){
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_POST,1);
		curl_setopt($ch,CURLOPT_POSTFIELDS,  $payload);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	  	curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);

		if($header)  curl_setopt($ch, CURLOPT_HEADER, true);

		$result = curl_exec($ch);

		// catch error
		if($result === false) {
			throw new \SoapFault('Sender', 'Curl error: ' . curl_error($ch));
		}

		curl_close($ch);

		return $result;
	}