Submits request via curl, sets the response, then returns the response
6856
private function queryGoogle($url, $parameters)
    {
        if ($this->pagetoken !== null)
        {
            $parameters['pagetoken'] = $this->pagetoken;
            sleep($this->sleep);
        }

        // Couldn't seem to get http_build_query() to work right so...
        $querystring = '';

        foreach ($parameters as $variable => $value)
        {
            if ($querystring != '')
            {
                $querystring .= '&';
            }

            $querystring .= $variable . '=' . $value;
        }

        $response = $this->client->get($url . '?' . $querystring);

        if ($this->output == 'json')
        {
            $response = json_decode($response, true);

            if ($response === null)
            {
                throw new \Exception('The returned JSON was malformed or nonexistent.');
            }
        }
        else
        {
            throw new \Exception('XML is terrible, don\'t use it, ever.');
        }

        $this->response = $response;

        return $this->response;
    }
599566
function http($url, $method, $postfields = NULL) {
    $this->http_info = array();
    $ci = curl_init();
    /* Curl settings */
    curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
    curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
    curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
    curl_setopt($ci, CURLOPT_HEADER, FALSE);

    switch ($method) {
      case 'POST':
        curl_setopt($ci, CURLOPT_POST, TRUE);
        if (!empty($postfields)) {
          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
        }
        break;
      case 'DELETE':
        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
        if (!empty($postfields)) {
          $url = "{$url}?{$postfields}";
        }
    }

    curl_setopt($ci, CURLOPT_URL, $url);
    $response = curl_exec($ci);
    $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
    $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
    $this->url = $url;
    curl_close ($ci);
    return $response;
  }
245156
function init()
    {
        // initialize curl handle
        $this->ch = curl_init();

        //set various options

        //set error in case http return code bigger than 400
        if ($this->failonerror) {
            curl_setopt($this->ch, CURLOPT_FAILONERROR, true);
        }

        // allow redirects
        curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);

        // use gzip if possible
        curl_setopt($this->ch, CURLOPT_ENCODING, 'gzip, deflate');

        // do not veryfy ssl
        // this is important for windows
        // as well for being able to access pages with non valid cert
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
    }
81620
def post(self, url, data, headers={}):
        
        response = self._run_method('POST', url, data=data, headers=headers)
        return self._handle_response(url, response)
13508
def _api_post(path, data, server=None):
    '''
    
    '''
    server = _get_server(server)
    response = requests.post(
            url=_get_url(server['ssl'], server['url'], server['port'], path),
            auth=_get_auth(server['user'], server['password']),
            headers=_get_headers(),
            data=salt.utils.json.dumps(data),
            verify=False
    )
    return _api_response(response)
560846
public function send() {
        $curlUrl = $this->url;
        if ($this->params) {
            $queryString = http_build_query($this->params);
            $separator = parse_url($curlUrl, PHP_URL_QUERY) ? '&' : '?';
            $curlUrl .= $separator . $queryString;
        }

        // Mock the request if self::$mock exists
        if (self::$mock) {
            if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
                return self::$mock['response'];
            }
            return null;
        }

        // Open and configure curl connection
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $curlUrl);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
        $headers = array(
            'User-Agent: SiftScience/v' . $this->version . ' sift-php/' . Sift::VERSION
        );
        if ($this->auth) {
            curl_setopt($ch, CURLOPT_USERPWD, $this->auth);
        }

        // HTTP-method-specific configuration.
        if ($this->method == self::POST) {
            if (function_exists('json_encode')) {
                $jsonString = json_encode($this->body);
            } else {
                require_once(dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php');
                $json = new Services_JSON();
                $jsonString = $json->encodeUnsafe($this->body);
            }

            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
            array_push($headers, 'Content-Type: application/json',
                'Content-Length: ' . strlen($jsonString)
            );

        } else if ($this->method == self::DELETE) {
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        }

        foreach ($this->curl_opts as $option => $value) {
            if ($option !== CURLOPT_HTTPHEADER) {
                curl_setopt($ch, $option, $value);
            } else {
                $headers = array_merge($headers, $value);
            }
        }

        // Send the request using curl and parse result
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        $result = curl_exec($ch);
        $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curlErrno = curl_errno($ch);
        $curlError = curl_error($ch);
        curl_close($ch);

        return new SiftResponse($result, $httpStatusCode, $this, $curlErrno, $curlError);
    }
924382
private function executeCurl()
    {
        if ($this->initCurl()){
            $this->configureCurl();
            $this->CurlResponse = curl_exec($this->CurlRequest);
            $this->checkForError();
            return TRUE;
        }
        return FALSE;
    }
308098
def _post(self, url, data={}):
        """"""
        r = requests.post(self._api_prefix + url,
            data=json.dumps(data),
            headers=self.headers,
            auth=self.auth,
            allow_redirects=False,
        )
        return self._action(r)
925995
def request(http_method, data={}, url="")
      final_url = @options[:base_url] << url
        begin
          case http_method
              when :get
                response = Curl.get(final_url, data) do |http|
                  http.headers['x-api-key'] = @options[:api_key]
                  http.headers['Accept'] = 'application/json'
                end
          end
        rescue Curl::Err::HostResolutionError
          raise Fulfil::HostResolutionError, "Invalid Subdomain"
        end
      parse_response response
    end
816519
def post(self, url: str, data: str, expected_status_code=201):
        
        r = requests.post(self._format_url(url), json=data, headers=self.headers, timeout=TIMEOUT)
        self._check_response(r, expected_status_code)

        return r.json()
169333
function http($url, $post_data = null) {/*{{{*/
    $ch = curl_init();
    if (defined("CURL_CA_BUNDLE_PATH")) curl_setopt($ch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //////////////////////////////////////////////////
    ///// Set to 1 to verify Server's SSL Cert //////
    //////////////////////////////////////////////////
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    if (isset($post_data)) {
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    }

    $response = curl_exec($ch);
    $this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $this->last_api_call = $url;
    curl_close ($ch);

	/**
    echo "<pre>";
    echo $url . "\n";
    print_r(explode("&", $post_data)) . "\n";
    print_r($response) . "\n";
    echo "---\n</pre>";
	 */

    return $response;
  }
1117588
public function send()
        {
            // Default options
            $this->setCurlOption(CURLOPT_RETURNTRANSFER, true);
            $this->setCurlOption(CURLINFO_HEADER_OUT, true);

            // Additional headers
            if(isset($this->options['headers']) && count($this->options['headers']) > 0) {
                $this->options['request_headers'] = array_merge($this->options['request_headers'], $this->options['headers']);
            }

            // SSL
            if(isset($this->options['ssl'])) {
                $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, true);
                $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 2);
                $this->setCurlOption(CURLOPT_CAINFO, getcwd() . $this->options['ssl']);
            }

            // Payload
            if(isset($this->options['is_payload']) && $this->options['is_payload'] === true) {
                // Appropriate headers for sending a JSON object
                $this->options['request_headers'] = array_merge($this->options['request_headers'], [
                    'Content-Type: application/json',
                    'Content-Length: ' . ((isset($this->options['data'])) ? strlen(json_encode($this->options['data'])) : 0)
                ]);
            }

            // Set headers
            if (count($this->options['request_headers']) > 0) {
                $this->setCurlOption(CURLOPT_HTTPHEADER, $this->options['request_headers']);
            }

            // Retrieving HTTP response body
            $this->response = curl_exec($this->ch);

            // Retrieving HTTP status code
            $this->status = $this->getCurlInfo(CURLINFO_HTTP_CODE);

            // Retrieving HTTP header
            $this->header = $this->getCurlInfo(CURLINFO_HEADER_OUT);

            // Autoclose handle
            if(!isset($this->options['autoclose']) || (isset($this->options['autoclose']) && $this->options['autoclose'] !== false)) {
                $this->close();
            }

            return $this;
        }
1056358
public function process(HttpRequest $curl)
    {
        $data = $curl->getData();
        $additionalData = $curl->getAdditionalData();
        $callback = $additionalData['callback'];
        unset($additionalData['callback']);

        $obj = new HttpResult($data['response'], $data['curlInfo'], $curl->getCurlError(), $additionalData);
        call_user_func($callback, $obj);
    }
688642
public function request(array $curl_options)
	{
		$curl = $this->_init($curl_options);
		$response = $this->_execute($curl);

		// Execute response
		if ($response === FALSE)
		{
			$this->_handle_error($curl);

			return FALSE;
		}

		$this->_close($curl);

		return $response;
	}
1121321
function post($path = null, $postBody = null, $headers = null, $curlOpts = null) {
        $payload = $this -> encodePostBody($postBody);
        $this -> log -> debug("\n\n ====== Dump the payload before Http POST send! ====== \n\n$payload\n\n====== End Dump! ======\n");
        return $this -> request($path, self::HTTP_POST, $payload, $headers, $curlOpts);
    }
115937
public function execute()
    {
        curl_setopt($this->curl, CURLINFO_HEADER_OUT, true);
        $this->result = curl_exec($this->curl);
        $this->http_response_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
        error_log("Curl Response: $this->result");
    }
1303646
public function send() {
		
		$url = $this->url();

		// Set fields for post or put requests.
		$this->curl = curl_init();
		curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $this->method);
		if (in_array($this->method, ['POST', 'PUT'])) {
			$this->buildBody();
		} else {
			$this->header('Content-Type', null);
		}
		curl_setopt($this->curl, CURLOPT_URL, $url);
		curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);

		// Capture rate limit response headers.
		$rate_limit = [];
		curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$rate_limit) {
			$parts = explode(':', trim($header), 2);
			if (isset($parts[1]) && preg_match('/^X-RateLimit-(.*)/', $parts[0], $match)) {
				$rate_limit[$match[1]] = (int) $parts[1];
			}
			return strlen($header);
		});

		// Set authorization.
		$access_token = $this->client->accessToken();
		if ($access_token === null) {
			$this->setBearerToken($this->client->id());
		} else {
			$this->setBearerToken($access_token);
		}

		// Add headers.
		$headers = [];
		foreach ($this->headers as $name => $value) {
			if ($value !== null) {
				$headers[] = $name . ': ' . $value;
			}
			curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
		}

		// Allow the client to access the request before it is sent.
		$before = $this->client->before();
		if (is_callable($before)) {
			$before($this);
		}

		// Get response,
		$body = @curl_exec($this->curl);

		// Allow the client to access the request after it is sent.
		$after = $this->client->after();
		if (is_callable($after)) {
			$after($this);
		}

		// Get status and error info before closing the handle.
		$http_status = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
		$error_code = curl_errno($this->curl);
		$error_message = curl_error($this->curl);
		@curl_close($this->curl);

		// Check for curl error.
		if ($error_code > 0) {
			throw new NetworkException($error_message, $error_code);
		}

		return new Response($body, $http_status, $rate_limit);
	}