[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

(no description)

File Size: 873 lines (33 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()
  time()
  parseHeaders()
  buildHeaders()
  getCookies()
  postEncode()
  postMultipartEncode()
  uniqueConnectionId()


Class: HTTPClient  - X-Ref

This class implements a basic HTTP client

It supports POST and GET, Proxy usage, basic authentication,
handles cookies and referers. 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;

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

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.

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
author: Andreas Gohr <andi@splitbrain.org>

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

Returns the resulting page or false on an error;

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

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.

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
author: Andreas Goetz <cpuidle@gmx.de>
author: Andreas Gohr <andi@splitbrain.org>

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

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

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.

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
author: Tom N Harris <tnharris@whoopdedo.org>

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

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

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

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

Uses _debug_text or _debug_html depending on the SAPI name

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

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

time()   X-Ref
Return current timestamp in microsecond resolution

return: float

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

All Keys are lowercased.

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

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

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

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

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

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

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

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

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

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

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