[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/HTTP/ -> HTTPClient.php (summary)

(no description)

File Size: 906 lines (34 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

HTTPClient:: (19 methods):
  __construct()
  get()
  dget()
  post()
  sendRequest()
  ssltunnel()
  sendData()
  readData()
  readLine()
  debug()
  debugHtml()
  debugText()
  parseHeaders()
  buildHeaders()
  getCookies()
  postEncode()
  postMultipartEncode()
  uniqueConnectionId()
  useProxyForUrl()


Class: HTTPClient  - X-Ref

This class implements a basic HTTP client

It supports POST and GET, Proxy usage, basic authentication,
handles cookies and referrers. It is based upon the httpclient
function from the VideoDB project.

__construct()   X-Ref
Constructor.

author: Andreas Gohr <andi@splitbrain.org>

get($url, $sloppy304 = false)   X-Ref
Simple function to do a GET request

Returns the wanted page or false on an error;

author: Andreas Gohr <andi@splitbrain.org>
param: string $url The URL to fetch
param: bool $sloppy304 Return body on 304 not modified
return: false|string  response body, false on error

dget($url, $data, $sloppy304 = false)   X-Ref
Simple function to do a GET request with given parameters

Returns the wanted page or false on an error.

This is a convenience wrapper around get(). The given parameters
will be correctly encoded and added to the given base URL.

author: Andreas Gohr <andi@splitbrain.org>
param: string $url The URL to fetch
param: array $data Associative array of parameters
param: bool $sloppy304 Return body on 304 not modified
return: false|string  response body, false on error

post($url, $data)   X-Ref
Simple function to do a POST request

Returns the resulting page or false on an error;

author: Andreas Gohr <andi@splitbrain.org>
param: string $url The URL to fetch
param: array $data Associative array of parameters
return: false|string  response body, false on error

sendRequest($url, $data = '', $method = 'GET')   X-Ref
Send an HTTP request

This method handles the whole HTTP communication. It respects set proxy settings,
builds the request headers, follows redirects and parses the response.

Post data should be passed as associative array. When passed as string it will be
sent as is. You will need to setup your own Content-Type header then.

author: Andreas Goetz <cpuidle@gmx.de>
author: Andreas Gohr <andi@splitbrain.org>
param: string $url - the complete URL
param: mixed $data - the post data either as array or raw data
param: string $method - HTTP Method usually GET or POST.
return: bool - true on success

ssltunnel(&$socket, &$requesturl)   X-Ref
Tries to establish a CONNECT tunnel via Proxy

Protocol, Servername and Port will be stripped from the request URL when a successful CONNECT happened

param: resource &$socket
param: string   &$requesturl
return: bool true if a tunnel was established

sendData($socket, $data, $message)   X-Ref
Safely write data to a socket

author: Tom N Harris <tnharris@whoopdedo.org>
param: resource $socket An open socket handle
param: string $data The data to write
param: string $message Description of what is being read

readData($socket, $nbytes, $message, $ignore_eof = false)   X-Ref
Safely read data from a socket

Reads up to a given number of bytes or throws an exception if the
response times out or ends prematurely.

author: Tom N Harris <tnharris@whoopdedo.org>
param: resource $socket An open socket handle in non-blocking mode
param: int $nbytes Number of bytes to read
param: string $message Description of what is being read
param: bool $ignore_eof End-of-file is not an error if this is set
return: string

readLine($socket, $message)   X-Ref
Safely read a \n-terminated line from a socket

Always returns a complete line, including the terminating \n.

author: Tom N Harris <tnharris@whoopdedo.org>
param: resource $socket An open socket handle in non-blocking mode
param: string $message Description of what is being read
return: string

debug($info, $var = null)   X-Ref
print debug info

Uses _debug_text or _debug_html depending on the SAPI name

author: Andreas Gohr <andi@splitbrain.org>
param: string $info
param: mixed $var

debugHtml($info, $var = null)   X-Ref
print debug info as HTML

param: string $info
param: mixed $var

debugText($info, $var = null)   X-Ref
prints debug info as plain text

param: string $info
param: mixed $var

parseHeaders($string)   X-Ref
convert given header string to Header array

All Keys are lowercased.

author: Andreas Gohr <andi@splitbrain.org>
param: string $string
return: array

buildHeaders($headers)   X-Ref
convert given header array to header string

author: Andreas Gohr <andi@splitbrain.org>
param: array $headers
return: string

getCookies()   X-Ref
get cookies as http header string

author: Andreas Goetz <cpuidle@gmx.de>
return: string

postEncode($data)   X-Ref
Encode data for posting

author: Andreas Gohr <andi@splitbrain.org>
param: array $data
return: string

postMultipartEncode($data)   X-Ref
Encode data for posting using multipart encoding

author: Andreas Gohr <andi@splitbrain.org>
param: array $data
return: string

uniqueConnectionId($server, $port)   X-Ref
Generates a unique identifier for a connection.

param: string $server
param: string $port
return: string unique identifier

useProxyForUrl($url)   X-Ref
Should the Proxy be used for the given URL?

Checks the exceptions

param: string $url
return: bool