Initializes curl resource with options.

@param string $url
@param string $postString
@param array $headers
@return $this
749
protected function init($url, $postString, $headers)
    {
        $this->headers = $headers;

        $this->curl = curl_init($url);

        if (empty($this->cookieJar)) {
            $this->loadCookies();
        }

        curl_setopt_array($this->curl, $this->makeHttpOptions($postString));

        return $this;
    }
5200
public function postRequest(string $url, array $requestHeaders = [], array $postFields = [], bool $returnResponseHeaders = false)
    {
        $handle = $this->createCurlHandle($url);

        if (Config::get('hpProxy')) {
            $handle->setOption(CURLOPT_PROXY, Config::get('hpProxy'));
        }

        if ($returnResponseHeaders) {
            $handle->setOption(CURLOPT_HEADER, true);
        }

        if (!empty($requestHeaders)) {
            $handle->setOption(CURLOPT_HTTPHEADER, $this->prepareHeaders($requestHeaders));
        }

        if (!empty($postFields)) {
            $handle->setOption(CURLOPT_POST, true);
            $handle->setOption(CURLOPT_POSTFIELDS, http_build_query($postFields));
        }

        $response = $handle->execute();

        $statusCode = $handle->getInfo(CURLINFO_HTTP_CODE);
        $handle->close();

        if ($response && $returnResponseHeaders) {
            return $this->splitResponseHeaderAndBody($response, $statusCode);
        }

        return $response;
    }
259665
public function curlGet( $url, array $params = array() )
  {
    if ( count( $params ) )
    {
      $url .= '?' . $this->generatePostFields( $params );
    }

    $this->setCurlParam( CURLOPT_URL, $url );
    $this->requestMethod = self::GET;

    return $this;
  }
531009
public static function get($url, $httpHeaders = array())
    {
        self::prepareRequest($httpHeaders);

        $response = CurlRequest::get($url, self::$httpHeaders);

        return self::processResponse($response);
    }
721428
public function get($url,  array $headers = [], array $params = [])
    {
        return $this->instance->createHttpClient()->get($url, $headers, $params);
    }
1191031
private function curl( $url, $headerParams, $post = true ) {

		$authHeader	= $this->generateAuthHeader( $headerParams );
		$authHeader	= [ $authHeader, 'Expect:' ];

		$ch = curl_init();

		curl_setopt( $ch, CURLOPT_HTTPHEADER, $authHeader );
		curl_setopt( $ch, CURLOPT_HEADER, false );
		curl_setopt( $ch, CURLOPT_URL, $url );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

		if( $post ) {

			curl_setopt( $ch, CURLOPT_POST, true );
		}

		curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

		$data = curl_exec( $ch );

		curl_close( $ch );

		return $data;
	}
1226673
private function parseHeader($curl, $headers)
    {
        if (!$this->responseStatusLine && strpos($headers, 'HTTP/') === 0) {
            $this->responseStatusLine = $headers;
        } else {
            $parts = explode(': ', $headers);
            if (isset($parts[1])) {
                $this->responseHeaders[$parts[0]] = trim($parts[1]);
            }
        }
        return strlen($headers);
    }
592204
private function initCurl(array $curlOptions)
    {
        $curlResource = curl_init();
        foreach ($curlOptions as $option => $value) {
            curl_setopt($curlResource, $option, $value);
        }

        return $curlResource;
    }
780557
public static function connect($url, $headers = [], $parameters = null)
    {
        return Request::create('default')->connect($url, $headers, $parameters);
    }
1121597
public function post($url, $data, array $headers = array())
    {
        curl_setopt($this->handle, CURLOPT_POST, true);
        curl_setopt($this->handle, CURLOPT_POSTFIELDS, $data);

        return $this->execute($url, $headers);
    }
700168
public function curlPost($url, array $params = [], array $opts = [])
    {
        $options = [
            CURLOPT_POST    => true,
            CURLOPT_URL     => $url,
        ];
        foreach ($opts as $key => $value) {
            if ($key !== CURLOPT_POST && $key !== CURLOPT_URL) {
                $options[$key] = $value;
            }
        }
        if (!array_key_exists(CURLOPT_POSTFIELDS, $options)) {
            $options[CURLOPT_POSTFIELDS] = $this->params($params);
        }

        return self::curl($options);
    }
125957
private static function _curlInit($url, $headers) {
		$curl	= curl_init();
		if( stripos( $url, 'https://') !== FALSE ) {
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
		}

		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_HEADER, 0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		if ( is_array($headers) ) {
			$_headers = array();
			foreach ( $headers as $key => $value ) {
				$_headers[] = "{$key}:$value";
			}
			curl_setopt($curl, CURLOPT_HTTPHEADER, $_headers);
		}
		return $curl;
	}
997484
public static function head($url, $headers = [], $parameters = null)
    {
        return Request::create('default')->head($url, $headers, $parameters);
    }
107997
private function send($url, array $data = [], array $headers = [])
    {
        // Set incoming parameters as cURL options
        $this->setUrl($url);
        $this->setData($data);
        $this->setHeaders($headers);

        return $this->executeCurlRequest();
    }
846582
protected function initRequest($url, $options = array()) {
		$ch = curl_init();
		//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // error with open_basedir or safe mode
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

		if (isset($options['referer'])) {
			curl_setopt($ch, CURLOPT_REFERER, $options['referer']);
		}

		if (isset($options['headers'])) {
			curl_setopt($ch, CURLOPT_HTTPHEADER, $options['headers']);
		}

		if (isset($options['query'])) {
			$url_parts = parse_url($url);
			if (isset($url_parts['query'])) {
				$query = $url_parts['query'];
				if (strlen($query) > 0) {
					$query .= '&';
				}
				$query .= http_build_query($options['query']);
				$url = str_replace($url_parts['query'], $query, $url);
			}
			else {
				$url_parts['query'] = $options['query'];
				$new_query = http_build_query($url_parts['query']);
				$url .= '?' . $new_query;
			}
		}

		if (isset($options['data'])) {
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $options['data']);
		}

		curl_setopt($ch, CURLOPT_URL, $url);
		return $ch;
	}
141363
public function post($url, $body, array $headers = [])
    {
        $request = $this->getClient()->createRequest('POST', $url, ['body' => $body]);
        $request->addHeaders($headers);

        return $this->sendRequest($request);
    }
1365763
public function call($method, $url, array $post = array(), array $headers = array())
    {
        $options = array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HTTPHEADER => $headers,
        );
        switch ($method) {
            case HttpMethod::GET:
                $options[CURLOPT_POST] = false;
                break;
            case HttpMethod::POST:
                $options[CURLOPT_POST] = true;
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            case HttpMethod::PUT:
                $options[CURLOPT_CUSTOMREQUEST] = 'PUT';
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            case HttpMethod::DELETE:
                $options[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                $options[CURLOPT_POSTFIELDS] = json_encode($post);
                break;
            default:
                throw new InvalidArgumentException(sprintf('Invalid method: %s', $method));
        }

        $this->curl->init();
        $this->curl->setOptArray($options);
        $rawResponse = $this->curl->exec(1, true);
        $contentType = $this->curl->getInfo(CURLINFO_CONTENT_TYPE);
        if (strpos($contentType, self::CONTENT_TYPE_JSON) === false) {
            return $rawResponse;
        }
        $response = json_decode($rawResponse);
        if (!isset($response->response)) {
            throw new RuntimeException(sprintf('Unexpected response: %s', $rawResponse));
        }
        $response = $response->response;
        if ('OK' == @$response->status) {
            return $response;
        } elseif ('NOAUTH' == @$response->error_id || 'Authentication failed - not logged in' == @$response->error) {
            throw new TokenExpiredException($response);
        }
        throw new ServerException($response);
    }