Curl request

@param string      $url
@param string      $method
@param array       $postFields
@param null|string $apiUrl

@return array
977733
public function request(string $url, string $method = Request::METHOD_GET, array $postFields = [],
                            string $apiUrl = null): array
    {
        /** Building url */
        if (null === $apiUrl) {
            $apiUrl = $this->getApiUrl();
        }
        $url   = $apiUrl . $url;
        $query = [];

        /**
         * OAuth2 Key/Secret authentication
         *
         * @see https://developer.github.com/v3/#oauth2-keysecret
         */
        if (null !== $this->getClientId() && null !== $this->getClientSecret()) {
            $query['client_id']     = $this->getClientId();
            $query['client_secret'] = $this->getClientSecret();
        } /**
         * Basic authentication via OAuth2 Token (sent as a parameter)
         *
         * @see https://developer.github.com/v3/#oauth2-token-sent-as-a-parameter
         */ else if ($this->getAuthentication() === self::OAUTH2_PARAMETERS_AUTH) {
            $query['access_token'] = $this->getToken();
        }

        /**
         * Pagination
         * Requests that return multiple items will be paginated to 30 items by default.
         * You can specify further pages with the ?page parameter.
         * For some resources, you can also set a custom page size up to 100 with the ?per_page parameter.
         * Note that for technical reasons not all endpoints respect the ?per_page parameter,
         *
         * @see https://developer.github.com/v3/#pagination
         */
        if (null !== $this->getPagination()) {
            if (null !== $this->getPagination()->getPage()) {
                $query['page'] = $this->getPagination()->getPage();
            }
            if (null !== $this->getPagination()->getLimit()) {
                $query['per_page'] = $this->getPagination()->getLimit();
            }
        }

        /**
         * Add URL-encoded query string parameters
         */
        if (!empty($query)) {
            $url .= (strstr($url, '?') !== false ? '&' : '?');
            $url .= http_build_query($query);
        }

        /** Call curl */
        $curl = new CurlClient();
        $curl->setOption([
            CURLOPT_USERAGENT      => self::USER_AGENT,
            CURLOPT_TIMEOUT        => $this->getTimeout(),
            CURLOPT_HEADER         => false, // Use $client->getHeaders() to get full header
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_HTTPHEADER     => [
                'Accept: ' . $this->getAccept(),
                'Content-Type: ' . $this->getContentType()
            ],
            CURLOPT_URL            => $url
        ]);

        /**
         * Basic authentication via username and Password
         *
         * @see https://developer.github.com/v3/auth/#via-username-and-password
         */
        if (!empty($this->getHttpAuth())) {
            if (!isset($this->getHttpAuth()['password']) || empty($this->getHttpAuth()['password'])) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => $this->getHttpAuth()['username']
                ]);
            } else {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => sprintf('%s:%s', $this->getHttpAuth()['username'],
                        $this->getHttpAuth()['password'])
                ]);
            }
        }

        if (!empty($this->getToken()) && $this->getAuthentication() !== self::OAUTH2_PARAMETERS_AUTH) {
            /**
             * Basic authentication via OAuth token
             *
             * @see https://developer.github.com/v3/auth/#via-oauth-tokens
             **/
            if ($this->getAuthentication() === self::OAUTH_AUTH) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
                    CURLOPT_USERPWD  => sprintf('%s:x-oauth-basic', $this->getToken())
                ]);
            } /**
             * Basic authentication via OAuth2 Token (sent in a header)
             *
             * @see https://developer.github.com/v3/#oauth2-token-sent-in-a-header
             */ else if ($this->getAuthentication() === self::OAUTH2_HEADER_AUTH) {
                $curl->setOption([
                    CURLOPT_HTTPAUTH   => CURLAUTH_BASIC,
                    CURLOPT_HTTPHEADER => [sprintf('Authorization: token %s', $this->getToken())]
                ]);
            }
        }

        /** Methods */
        switch ($method) {
            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7 */
            case Request::METHOD_DELETE:
                /** @see http://tools.ietf.org/html/rfc5789 */
            case Request::METHOD_PATCH:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_POST          => true,
                    CURLOPT_POSTFIELDS    => json_encode(array_filter($postFields))
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.3 */
            case Request::METHOD_GET:
                $curl->setOption(CURLOPT_HTTPGET, true);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4 */
            case Request::METHOD_HEAD:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_NOBODY        => true
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5 */
            case Request::METHOD_POST:
                $curl->setOption([
                    CURLOPT_POST       => true,
                    CURLOPT_POSTFIELDS => json_encode(array_filter($postFields))
                ]);
                break;

            /** @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 */
            case Request::METHOD_PUT:
                $curl->setOption([
                    CURLOPT_CUSTOMREQUEST => $method,
                    CURLOPT_PUT           => true,
                    CURLOPT_HTTPHEADER    => [
                        'X-HTTP-Method-Override: PUT',
                        'Content-type: application/x-www-form-urlencoded'
                    ]
                ]);
                break;

            default:
                break;
        }

        $curl->success(function (CurlClient $instance) {
            $this->headers = $instance->getHeaders();
            $this->success = $instance->getResponse();
            $data          = json_decode($this->success, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                $this->success = $data;
            }
        });
        $curl->error(function (CurlClient $instance) {
            $this->headers = $instance->getHeaders();
            $this->failure = $instance->getResponse();
            $data          = json_decode($this->failure, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                $this->failure = $data;
            }
        });
        $curl->perform();

        return (array)($this->success ?? $this->failure);
    }
248875
public function call($url, $method = 'GET', $params = [])
    {
        // Set call parameters
        $params = array_merge($this->params, is_array($params)? $params : []);

        // Setup parameters
        $content = '';
        $queryString = http_build_query($params);
        if ($method === 'GET') {
            $url = $url . '?' . $queryString;
        } else {
            $content = $queryString;
        }

        // Make call
        $result = @file_get_contents($url, false, stream_context_create([
            'http' => [
                'method'  => $method,
                'header'  => 'Content-type: application/x-www-form-urlencoded',
                'content' => $content
            ]
        ]));

        // Return result
        return $result;
    }
1289330
public function request($url, $method = 'get', $data = null, $curlOptions = array())
    {
        if (strtolower($method) === 'get')
        {
            $this->setGetfield($data);
        }
        else
        {
            $this->setPostfields($data);
        }

        return $this->buildOauth($url, $method)->performRequest(true, $curlOptions);
    }
1313970
protected function curl($url, $postFields = null)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_FAILONERROR, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //https 请求
        if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        if (is_array($postFields) && 0 < count($postFields)) {
            $postBodyString = "";
            foreach ($postFields as $k => $v) {
                $postBodyString .= "$k=" . urlencode($v) . "&"; 
            }
            unset($k, $v);
            curl_setopt($ch, CURLOPT_POST, true);
            $header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8");
            curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
            curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1));
        }
        $reponse = curl_exec($ch);
        return $reponse;
    }
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;
    }
67577
private function curlPost($url,$postFields){
		$postFields = http_build_query($postFields);
		$ch = curl_init ();
		curl_setopt ( $ch, CURLOPT_POST, 1 );
		curl_setopt ( $ch, CURLOPT_HEADER, 0 );
		curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $ch, CURLOPT_URL, $url );
		curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
		$result = curl_exec ( $ch );
		curl_close ( $ch );
		return $result;
	}
133843
protected function query($method, $url, array $parameters = null)
    {
        return $this->httpClient->query($method, $url, $parameters);
    }
1244944
public function call($method, $url, array $vars = array()) {

        // initiate request, pass options
        $this->request = curl_init();
        $this->setOptions($this->options);

        // enable logging to file
        if(!empty($this->log_file)) {
            $f = @fopen($this->log_file, 'a');
            @curl_setopt($this->request, CURLOPT_VERBOSE, true);
            @curl_setopt($this->request, CURLOPT_STDERR, $f);
        }

        // if the base uri was included in options, treat url as a relative url
        if(!empty($this->base_uri)) {
            $url = $this->base_uri.$url;
        }
        curl_setopt($this->request, CURLOPT_URL, $url);

        // set additional headers
        if(array_key_exists('headers', $vars) && is_array($vars['headers'])) {
            $this->setHeaders($vars['headers']);
            unset($vars['headers']);
        }

        // set proper curl option depending on what is declared HTTP method
        $this->setMethod($method);

        // set params for POST request
        if(!empty($vars['form_params'])) {
            curl_setopt($this->request, CURLOPT_POSTFIELDS, http_build_query($vars['form_params'], '', '&'));
        }

        // send request, parse returned response
        $response = curl_exec($this->request);

        $httpCode = curl_getinfo($this->request, CURLINFO_HTTP_CODE);

        // split returned response string into headers and body
        list($headers, $body) = $this->prepareResponse($response);

        if($response === false) {
            throw new MonetivoException('API error: '.curl_errno($this->request).' - '.curl_error($this->request), 0, $httpCode);
        }

        $response = new ApiResponse($headers, $body, $httpCode);

        // close resources
        curl_close($this->request);
        if(isset($f) && is_resource($f))
        {
            fclose($f);
        }

        return $response;
    }
475623
public function request($method, $url, $params = array())
    {
        if (mb_substr($url, 0, 1, 'UTF-8') === '/') {
            $url = $this->api_endpoint . $url;
        }

        $remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
        $session_id  = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
            mt_rand(0, 0xffff),
            mt_rand(0, 0x0fff) | 0x4000,
            mt_rand(0, 0x3fff) | 0x8000,
            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
        );
        $user_agent  = sprintf("%s/%s PHP/%s %s",
            self::USER_AGENT,
            self::VERSION,
            phpversion(),
            $this->platform
        );

        $headers = [
            'Accept: application/json',
            'Session-Id: ' . $session_id,
            'Forwarded: ' . $remote_addr,
            'Authorization:  Bearer ' . $this->merchant_token,
            'Content-Type: application/json'
        ];

        curl_setopt_array($this->curl, [
            CURLOPT_USERAGENT     => $user_agent,
            CURLOPT_HTTPHEADER    => $headers,
            CURLOPT_URL           => $url,
            CURLOPT_CUSTOMREQUEST => $method
        ]);

        if (count($params) > 0) {
            $data      = json_encode($params, JSON_PRETTY_PRINT);
            $headers[] = 'Content-Length: ' . strlen($data);

            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $data);
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
        }

        $body = curl_exec($this->curl);
        $info = curl_getinfo($this->curl);
        $code = (int)($info['http_code'] / 100);
        switch ($code) {
            case 0:
                $error = curl_error($this->curl);
                $errno = curl_errno($this->curl);
                throw new Exception(sprintf('Error: %s. Code: %s.', $error, $errno));
            case 1:
                throw new Exception(sprintf('Invalid HTTP Code: %s', $info['http_code']));
            case 2:
            case 3:
                return new Response($body);
            case 4:
            case 5:
                throw new Exception(sprintf('API Error: %s. HTTP Code: %s', $body, $info['http_code']));
            default:
                throw new Exception(sprintf('Invalid HTTP Code: %s', $info['http_code']));
        }
    }
384926
public function _fetch ($url, $method, $params) {
		if (! extension_loaded ('curl')) {
			$this->error = 'cURL extension not loaded.';
			return false;
		}

		$ch = curl_init ();
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
		curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_VERBOSE, 0);
		curl_setopt ($ch, CURLOPT_HEADER, 1);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);

		/* HTTP Basic Authentication */
		if ($this->user && $this->password) {
			curl_setopt ($ch, CURLOPT_USERPWD, $this->user . ":" . $this->password);	
		}

		if ($this->request_format == 'xml') {
			$this->request_headers = array_merge ($this->request_headers, array ("Expect:", "Content-Type: text/xml", "Length: " . strlen ($params)));
		}
		switch ($method) {
			case 'POST':
				curl_setopt ($ch, CURLOPT_POST, 1);
				curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
				break;
			case 'DELETE':
				curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
				break;
			case 'PUT':
				curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
				curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
				break;
			case 'GET':
			default:
				break;
		}

		if (count ($this->request_headers)) {
			curl_setopt ($ch, CURLOPT_HTTPHEADER, $this->request_headers);
		}

		$res = curl_exec ($ch);

		$http_code = curl_getinfo ($ch, CURLINFO_HTTP_CODE);

		// Check HTTP status code for denied access
		if ($http_code == 401) {
			$this->errno = $http_code;
			$this->error = "HTTP Basic: Access denied.";
			curl_close ($ch);
			return false;
		}

		// Check HTTP status code for rate limit
		if ($http_code == 429) {
			if (preg_match ('/Retry-After: ([0-9]+)/', $res, $retry_after)) {
			  sleep(intval($retry_after[1]));
			  return $this->_fetch ($url, $method, $params);
			}
			$this->errno = $http_code;
			$this->error = "Too Many Requests";
			curl_close ($ch);
			return false;
		}

		if (! $res) {
			$this->errno = curl_errno ($ch);
			$this->error = curl_error ($ch);
			curl_close ($ch);
			return false;
		}

		curl_close ($ch);
		return $res;
	}
823511
public function call($resource, $params = array(), $method = 'GET')
    {
        if (!empty($params) && is_array($params)) {
          $queryString = http_build_query($params);
        }
        else {
          $queryString = '';
        }

        $requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');

        $curl = curl_init();

        $curl_options = array(
          CURLOPT_USERPWD => $this->getAuthenticationString(),
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_URL => $requestUrl,
          CURLOPT_TIMEOUT => 30,
          CURLOPT_CONNECTTIMEOUT => 30,
          CURLOPT_HTTPHEADER => array('Accept: application/xml'),
        );

        if (strtolower($method) == 'post') {
          $curl_options[CURLOPT_POST] = 1;
          $curl_options[CURLOPT_POSTFIELDS] = $params;
        }

        curl_setopt_array($curl, $curl_options);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        //@todo test for curl error
        if ($errno = curl_errno($curl)) {
          $error_message = $errno . ': ' . curl_strerror($errno);
          throw new Exception($error_message, $errno);
        }
        curl_close($curl);

        //@todo test for any non 200 response
        if ($curl_info['http_code'] != 200) {
            throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
        }

        $xmlObject = simplexml_load_string($response);

        if ($xmlObject === false) {
            throw new Exception("Response: Response was not valid XML");
        }

        return $xmlObject;
    }
591087
public static function inlineRequest($method, $path, $payload = null, $curlOptions = [])
    {
        if (null === $payload || 'null' == $payload) {
            $payload = [];
        }

        try {
            if ('https:/' == ($protocol = substr($path, 0, 7)) || 'http://' == $protocol) {
                $result = static::externalRequest($method, $path, $payload, $curlOptions);
            } else {
                $result = null;
                $params = (array)array_get($curlOptions, 'parameters');
                $headers = (array)array_get($curlOptions, 'headers');
                if (false !== $pos = strpos($path, '?')) {
                    $paramString = substr($path, $pos + 1);
                    if (!empty($paramString)) {
                        $pArray = explode('&', $paramString);
                        foreach ($pArray as $k => $p) {
                            if (!empty($p)) {
                                $tmp = explode('=', $p);
                                $name = array_get($tmp, 0, $k);
                                $value = array_get($tmp, 1);
                                $params[$name] = urldecode($value);
                            }
                        }
                    }
                    $path = substr($path, 0, $pos);
                }

                if (false === ($pos = strpos($path, '/'))) {
                    $serviceName = $path;
                    $resource = null;
                } else {
                    $serviceName = substr($path, 0, $pos);
                    $resource = substr($path, $pos + 1);

                    //	Fix removal of trailing slashes from resource
                    if (!empty($resource)) {
                        if ((false === strpos($path, '?') && '/' === substr($path, strlen($path) - 1, 1)) ||
                            ('/' === substr($path, strpos($path, '?') - 1, 1))
                        ) {
                            $resource .= '/';
                        }
                    }
                }

                if (empty($serviceName)) {
                    return null;
                }

                $format = DataFormats::PHP_ARRAY;
                if (!is_array($payload)) {
                    $format = DataFormats::TEXT;
                }

                $request = new ScriptServiceRequest($method, $params, $headers);
                $request->setContent($payload, $format);

                //  Now set the request object and go...
                $result = ServiceManager::handleServiceRequest($request, $serviceName, $resource);
            }
        } catch (\Exception $ex) {
            $result = static::exceptionToServiceResponse($ex);

            \Log::error('Exception: ' . $ex->getMessage(), ['response' => $result]);
        }

        static::formatResult($result);

        return ResponseFactory::sendScriptResponse($result);
    }
761199
public function curl($url, $params_data = array(), $verb = "", $custom_method = "") {
		if ($this->version == 1) {
			// find the method from the URL.
			$method = preg_match("/api_action=[^&]*/i", $url, $matches);
			if ($matches) {
				$method = preg_match("/[^=]*$/i", $matches[0], $matches2);
				$method = $matches2[0];
			} elseif ($custom_method) {
				$method = $custom_method;
			}
		} elseif ($this->version == 2) {
			$method = $custom_method;
			$url .= "?api_key=" . $this->api_key;
		}

		$debug_str1 = "";

		$request = curl_init();

		$debug_str1 .= "\$ch = curl_init();\n";

		curl_setopt($request, CURLOPT_HEADER, 0);
		curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout);

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_HEADER, 0);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_TIMEOUT, " . $this->timeout . ");\n";

		if ($params_data && $verb == "GET") {
			if ($this->version == 2) {
				$url .= "&" . $params_data;
				curl_setopt($request, CURLOPT_URL, $url);
			}
		}
		else {
			curl_setopt($request, CURLOPT_URL, $url);
			if ($params_data && !$verb) {
				// if no verb passed but there IS params data, it's likely POST.
				$verb = "POST";
			} elseif ($params_data && $verb) {
				// $verb is likely "POST" or "PUT".
			} else {
				$verb = "GET";
			}
		}

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_URL, \"" . $url . "\");\n";

		if ($this->debug) {
			$this->dbg($url, 1, "pre", "Description: Request URL");
		}

		if ($verb == "POST" || $verb == "PUT" || $verb == "DELETE") {
			if ($verb == "PUT") {
				curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_CUSTOMREQUEST, \"PUT\");\n";
			} elseif ($verb == "DELETE") {
				curl_setopt($request, CURLOPT_CUSTOMREQUEST, "DELETE");

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_CUSTOMREQUEST, \"DELETE\");\n";
			} else {
				$verb = "POST";
				curl_setopt($request, CURLOPT_POST, 1);

				$debug_str1 .= "curl_setopt(\$ch, CURLOPT_POST, 1);\n";
			}
			$data = "";
			if (is_array($params_data)) {
				foreach($params_data as $key => $value) {
					if (is_array($value)) {

						if (is_int($key)) {
							// array two levels deep
							foreach ($value as $key_ => $value_) {
								if (is_array($value_)) {
									foreach ($value_ as $k => $v) {
										$k = urlencode($k);
										$data .= "{$key_}[{$key}][{$k}]=" . urlencode($v) . "&";
									}
								} else {
									$data .= "{$key_}[{$key}]=" . urlencode($value_) . "&";
								}
							}
						} elseif (preg_match('/^field\[.*,0\]/', $key)) {
							// if the $key is that of a field and the $value is that of an array
							if (is_array($value)) {
								// then join the values with double pipes
								$value = implode('||', $value);
							}
							$data .= "{$key}=" . urlencode($value) . "&";
						} else {
							// IE: [group] => array(2 => 2, 3 => 3)
							// normally we just want the key to be a string, IE: ["group[2]"] => 2
							// but we want to allow passing both formats
							foreach ($value as $k => $v) {
								if (!is_array($v)) {
									$k = urlencode($k);
									$data .= "{$key}[{$k}]=" . urlencode($v) . "&";
								}
							}
						}

					} else {
						$data .= "{$key}=" . urlencode($value) . "&";
					}
				}
			} else {
				// not an array - perhaps serialized or JSON string?
				// just pass it as data
				$data = "data={$params_data}";
			}

			$data = rtrim($data, "& ");

			curl_setopt($request, CURLOPT_HTTPHEADER, array("Expect:"));

			$debug_str1 .= "curl_setopt(\$ch, CURLOPT_HTTPHEADER, array(\"Expect:\"));\n";

			if ($this->debug) {
				curl_setopt($request, CURLINFO_HEADER_OUT, 1);

				$debug_str1 .= "curl_setopt(\$ch, CURLINFO_HEADER_OUT, 1);\n";

				$this->dbg($data, 1, "pre", "Description: POST data");
			}

			curl_setopt($request, CURLOPT_POSTFIELDS, $data);

			$debug_str1 .= "curl_setopt(\$ch, CURLOPT_POSTFIELDS, \"" . $data . "\");\n";
		}

		curl_setopt($request, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);

		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYPEER, false);\n";
		$debug_str1 .= "curl_setopt(\$ch, CURLOPT_SSL_VERIFYHOST, 0);\n";

		$response = curl_exec($request);

		$curl_error = curl_error($request);
		
		if (!$response && $curl_error) {
			return $curl_error;
		}

		$debug_str1 .= "curl_exec(\$ch);\n";

		if ($this->debug) {
			$this->dbg($response, 1, "pre", "Description: Raw response");
		}

		$http_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
		if (!preg_match("/^[2-3][0-9]{2}/", $http_code)) {
			// If not 200 or 300 range HTTP code, return custom error.
			return "HTTP code $http_code returned";
		}

		$debug_str1 .= "\$http_code = curl_getinfo(\$ch, CURLINFO_HTTP_CODE);\n";

		if ($this->debug) {
			$this->dbg($http_code, 1, "pre", "Description: Response HTTP code");

			$request_headers = curl_getinfo($request, CURLINFO_HEADER_OUT);

			$debug_str1 .= "\$request_headers = curl_getinfo(\$ch, CURLINFO_HEADER_OUT);\n";

			$this->dbg($request_headers, 1, "pre", "Description: Request headers");
		}

		curl_close($request);

		$debug_str1 .= "curl_close(\$ch);\n";

		$object = json_decode($response);

		if ($this->debug) {
			$this->dbg($object, 1, "pre", "Description: Response object (json_decode)");
		}
		if ( !is_object($object) || (!isset($object->result_code) && !isset($object->succeeded) && !isset($object->success)) ) {
			// add methods that only return a string
			$string_responses = array("tags_list", "segment_list", "tracking_event_remove", "contact_list", "form_html", "tracking_site_status", "tracking_event_status", "tracking_whitelist", "tracking_log", "tracking_site_list", "tracking_event_list");
			if (in_array($method, $string_responses)) {
				return $response;
			}

			$this->throwRequestException($response);
		}

		if ($this->debug) {
			echo "<textarea style='height: 300px; width: 600px;'>" . $debug_str1 . "</textarea>";
		}

		$object->http_code = $http_code;

		if (isset($object->result_code)) {
			$object->success = $object->result_code;

			if (!(int)$object->result_code) {
				$object->error = $object->result_message;
			}
		} elseif (isset($object->succeeded)) {
			// some calls return "succeeded" only
			$object->success = $object->succeeded;

			if (!(int)$object->succeeded) {
				$object->error = $object->message;
			}
		}

		return $object;
	}
160384
function curl_post($url, $post) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, TRUE);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $json_response = curl_exec($curl);
        $this->last_response = $json_response;
        curl_close($curl);
        return $json_response;
    }
1050036
public function post($url, $params = '', $curlOptions = array()) {
        if (is_array($params)) {
            $params = $this->makePostFields($params);
        }
        $curlOptions['CURLOPT_POST'] = 1;
        $curlOptions['CURLOPT_POSTFIELDS'] = $params;
        return $this->request($url, $curlOptions);
    }
639841
public function request($method, $url, $params = null, $version = null, $headers = null)
    {
        $params = $params ?: [];
        $headers = $headers ?: [];
        if ($this->accessToken && $this->tokenType === 'Bearer') {
            $headers['Authorization'] = 'Bearer ' . $this->accessToken;
        }

        $payloadType = strcasecmp($method, 'get') === 0 ? 'query' : 'json';
        $client = $this->httpClient();

        if (!$this->noVersion) {
            $url = Sumup::getApiVersion() . '/' . $url;
        }

        try {
            $response = $client->request($method, $url, [
                $payloadType => $params,
                'headers' => $headers,
                'http_errors' => false
            ]);
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            throw new Error\ApiRequestorError($e->getMessage());
        }

        return new ApiResponse($response);
    }
488803
private function curl( $url, $count = 0, $postString = false ) {

		$ch = curl_init();

		curl_setopt( $ch, CURLOPT_URL, $url );
		curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );

		if( $postString ) {

			curl_setopt( $ch,CURLOPT_POST, $count );
			curl_setopt( $ch,CURLOPT_POSTFIELDS, $postString );
		}

		$data = curl_exec( $ch );

		curl_close( $ch );

		return $data;
	}