You are here

function cc::http_send in Constant Contact 6.2

Same name and namespace in other branches
  1. 6.3 class.cc.php \cc::http_send()
  2. 7.3 class.cc.php \cc::http_send()

* This does most the work of creating the HTTP request * *

Parameters

string The path of the resource to request eg. /index.php: * @param string The method to use to make the request eg. GET * @param array An array of params to use for this HTTP request, eg. post data * @param array An array of additional HTTP headers to send along with the request * * @access private

4 calls to cc::http_send()
cc::http_delete in ./class.cc.php
* Performs a HTTP DELETE * * * @access private
cc::http_get in ./class.cc.php
* Performs a HTTP GET * * * @access private
cc::http_post in ./class.cc.php
* Performs a HTTP POST * * * @access private
cc::http_put in ./class.cc.php
* Performs a HTTP PUT * * * @access private

File

./class.cc.php, line 1766

Class

cc
@file

Code

function http_send($path, $method, $params = array(), $headers = array()) {
  $this->http_response = '';
  $this->http_response_code = '';
  $this->http_method = $method;
  $this
    ->http_parse_request_url($path);
  $this
    ->http_headers_merge($headers);
  if (is_array($params)) {
    $params = $this
      ->http_serialize_params($params);
  }
  $method = strtoupper($method);
  $the_host = $this->http_url_bits['host'];
  $the_path = isset($this->http_url_bits['path']) && trim($this->http_url_bits['path']) != '' ? $this->http_url_bits['path'] : '';
  $the_path .= isset($this->http_url_bits['query']) && trim($this->http_url_bits['query']) != '' ? '?' . $this->http_url_bits['query'] : '';
  $this
    ->http_headers_add('', "{$method} {$the_path} HTTP/1.1");
  $this
    ->http_headers_add('Host', $the_host);
  if ($this->http_content_type) {
    $this
      ->http_headers_add('Content-Type', $this->http_content_type);
  }
  $this
    ->http_headers_add('User-Agent', $this->http_user_agent);
  $this
    ->http_headers_add('Content-Length', strlen($params));
  $request = $this
    ->http_build_request_headers();
  if (trim($params) != '') {
    $request .= "{$params}{$this->http_linebreak}";
  }
  $this->http_request = $request;
  if ($this->http_url_bits['scheme'] == 'https') {
    $port = 443;
    $fsockurl = "ssl://{$the_host}";
  }
  else {
    $port = 80;
    $fsockurl = $the_host;
  }

  // if no content-type heading variable is set we download the file instead
  if ($fp = fsockopen($fsockurl, $port, $errno, $errstr, $this->http_request_timeout)) {
    if (fwrite($fp, $request)) {
      while (!feof($fp)) {
        $this->http_response .= fread($fp, 4096);
      }
    }
    fclose($fp);
  }
  else {
    return false;
  }
  $this
    ->http_parse_response();
}