[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

(no description)

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

Defines 1 class

HTTPClient:: (20 methods):
  __construct()
  get()
  dget()
  post()
  sendRequest()
  ssltunnel()
  sendData()
  readData()
  readLine()
  debug()
  debugHtml()
  debugText()
  time()
  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 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;

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

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>
return: false|string  response body, false on error
param: string $url       The URL to fetch
param: array  $data      Associative array of parameters
param: bool   $sloppy304 Return body on 304 not modified

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>
return: false|string  response body, false on error
param: string $url       The URL to fetch
param: array  $data      Associative array of parameters

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>
return: bool - true on success
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.

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

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

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>
return: string
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

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>
return: string
param: resource $socket     An open socket handle in non-blocking mode
param: string   $message    Description of what is being read

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

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.

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

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

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

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>
return: string
param: array $data

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

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

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

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

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

Checks the exceptions

return: bool
param: string $url