Overview

Namespaces

  • None
  • PHP
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class
  • Tree

Class Http

An HTTP client that inspired by jQuery Ajax

Wei\Base
Extended by Wei\Http implements ArrayAccess, Countable, IteratorAggregate
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at Http.php
Methods summary
public
# __construct( array $options = array() )

Constructor

Constructor

Parameters

$options

Throws

InvalidArgumentException
When option "wei" is not an instance of "Wei\Wei"

Overrides

Wei\Base::__construct()
public mixed
# __invoke( array|string $url = null, array $options = array() )

Create a new HTTP object and execute

Create a new HTTP object and execute

Parameters

$url
A options array or the request URL
$options
A options array if the first parameter is string

Returns

mixed
$this A new HTTP object
public
# execute( )

Execute the request, parse the response data and trigger relative callbacks

Execute the request, parse the response data and trigger relative callbacks

protected array
# prepareCurlOptions( )

Prepare cURL options

Prepare cURL options

Returns

array
protected
# handleResponse( string $response )

Parse response text

Parse response text

Parameters

$response
protected
# triggerError( string $status, ErrorException $exception )

Trigger error callback

Trigger error callback

Parameters

$status
$exception
protected mixed
# parseResponse( string $data, null & $exception )

Parse response data by specified type

Parse response data by specified type

Parameters

$data
$exception
A variable to store exception when parsing error

Returns

mixed
public mixed
# setCurlOption( integer $option, mixed $value )

Sets an option on the current cURL handle

Sets an option on the current cURL handle

Parameters

$option
$value

Returns

mixed
$this
public null
# getCurlOption( integer $option )

Returns an option value of the current cURL handle

Returns an option value of the current cURL handle

Parameters

$option

Returns

null
public string
# getResponseText( )

Returns the response text

Returns the response text

Returns

string
public mixed
# getResponse( )

Returns the parsed response data

Returns the parsed response data

Returns

mixed
public string
# getUrl( )

Returns the request URL

Returns the request URL

Returns

string
public string
# getMethod( )

Returns the request method

Returns the request method

Returns

string
public string
# getIp( )

Returns the IP address for the host name in URL

Returns the IP address for the host name in URL

Returns

string
public array|string
# getData( )

Returns the data to send to the server

Returns the data to send to the server

Returns

array|string
public string|array
# getResponseHeader( string $name = null, boolean $first = true )

Returns request header value

Returns request header value

Parameters

$name
The header name
$first
Return the first element or the whole header values

Returns

string|array
When $first is true, returns string, otherwise, returns array
public array
# getResponseHeaders( )

Returns response headers array

Returns response headers array

Returns

array
public array
# getResponseCookies( )

Returns a key-value array contains the response cookies, like $_COOKIE

Returns a key-value array contains the response cookies, like $_COOKIE

Returns

array
public string|null
# getResponseCookie( string $name )

Returns the cookie value by specified name

Returns the cookie value by specified name

Parameters

$name

Returns

string|null
protected array
# parseCookie( string $header )

Parse cookie from header, returns result like $_COOKIE

Parse cookie from header, returns result like $_COOKIE

Parameters

$header

Returns

array
public boolean
# isSuccess( )

Returns if the request is success

Returns if the request is success

Returns

boolean
public mixed
# setMethod( string $method )

Set request method

Set request method

Parameters

$method

Returns

mixed
$this
public mixed
# get( string $url, array $data = array(), string $dataType = null )

Execute a GET method request

Execute a GET method request

Parameters

$url
$data
$dataType

Returns

mixed
$this
public mixed
# getJson( string $url, array $data = array() )

Execute a GET method request and parser response data to JSON array

Execute a GET method request and parser response data to JSON array

Parameters

$url
$data

Returns

mixed
$this
public mixed
# getJsonObject( string $url, array $data = array() )

Execute a GET method request and parser response data to JSON object

Execute a GET method request and parser response data to JSON object

Parameters

$url
$data

Returns

mixed
$this
public mixed
# post( string $url, array $data = array(), string $dataType = null )

Execute a POST method request

Execute a POST method request

Parameters

$url
$data
$dataType

Returns

mixed
$this
public mixed
# postJson( string $url, array $data = array() )

Execute a POST method request and parser response data to JSON array

Execute a POST method request and parser response data to JSON array

Parameters

$url
$data

Returns

mixed
$this
public mixed
# put( string $url, array $data = array(), string $dataType = null )

Execute a PUT method request

Execute a PUT method request

Parameters

$url
$data
$dataType

Returns

mixed
$this
public mixed
# delete( string $url, array $data = array(), string $dataType = null )

Execute a DELETE method request

Execute a DELETE method request

Parameters

$url
$data
$dataType

Returns

mixed
$this
public mixed
# patch( string $url, array $data = array(), string $dataType = null )

Execute a PATCH method request

Execute a PATCH method request

Parameters

$url
$data
$dataType

Returns

mixed
$this
public
# upload( mixed $url, mixed $data = array(), mixed $dataType = null )
protected mixed
# processMethod( string $url, array $data, string $dataType, string $method )

Execute a specified method request

Execute a specified method request

Parameters

$url
$data
$dataType
$method

Returns

mixed
$this
public string
# getErrorStatus( )

Returns the error status text

Returns the error status text

Returns

string
public ErrorException
# getErrorException( )

Returns the error exception object

Returns the error exception object

Returns

ErrorException
public boolean
# offsetExists( string $offset )

Check if the offset exists

Check if the offset exists

Parameters

$offset

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( string $offset )

Get the offset value

Get the offset value

Parameters

$offset

Returns

mixed

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( string $offset, mixed $value )

Set the offset value

Set the offset value

Parameters

$offset
$value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( string $offset )

Unset the offset

Unset the offset

Parameters

$offset

Implementation of

ArrayAccess::offsetUnset()
public integer
# count( )

Return the length of data

Return the length of data

Returns

integer
the length of data

Implementation of

Countable::count()
public ArrayIterator
# getIterator( )

Retrieve an array iterator

Retrieve an array iterator

Returns

ArrayIterator

Implementation of

IteratorAggregate::getIterator()
public string
# __toString( )

Returns to response body string

Returns to response body string

Returns

string
public array
# getCurlInfo( )

Returns

array
public
# __destruct( )

Close the cURL session

Close the cURL session

Methods inherited from Wei\Base
__call(), __get(), getOption(), setOption()
Properties summary
protected string $url

The request URL

The request URL

#
protected string $method

The HTTP request method

The HTTP request method

The method could be GET, POST, DELETE, PUT, PATCH or any other methods that the server is supported

# 'GET'
protected string $contentType

The content type in HTTP request header

The content type in HTTP request header

#
protected array $cookies

A key-value array to store cookies

A key-value array to store cookies

# array()
protected array|string $data

The data to send to the server

The data to send to the server

# array()
protected array $files

The files send to the server

The files send to the server

# array()
protected boolean $global

Whether use the global options in $wei->http object when create a new object

Whether use the global options in $wei->http object when create a new object

# false
protected array $headers

A key-value array to store request headers

A key-value array to store request headers

# array()
protected boolean $header

Whether includes the header in the response string, equals the CURLOPT_HEADER option Set to true when you need to call getResponseHeaders, getResponseHeader, getResponseCookies or getResponseCookie methods

Whether includes the header in the response string, equals the CURLOPT_HEADER option Set to true when you need to call getResponseHeaders, getResponseHeader, getResponseCookies or getResponseCookie methods

# false
protected string $ip

The IP address for the host name in URL, NOT your client IP

The IP address for the host name in URL, NOT your client IP

#
protected integer $timeout

A number of milliseconds to wait in the whole connection

A number of milliseconds to wait in the whole connection

#
protected string $dataType

The data type to parse the response body

The data type to parse the response body

The data type could by json, jsonObject, xml, query(URL query string), serialize and text

# 'text'
protected string|true $referer

The custom HTTP referer string

The custom HTTP referer string

If set to true, it will use the request URL as referer string

#
protected string $userAgent

The custom HTTP user agent string

The custom HTTP user agent string

#
protected boolean $throwException

Whether throw exception or keep silent when request error

Whether throw exception or keep silent when request error

Note that the exception is thrown after triggered complete callback, rather than triggered error callback

# true
protected callable $beforeSend

A callback triggered after prepared the data and before the process the request

A callback triggered after prepared the data and before the process the request

#
protected callable $success

A callback triggered after the request is called success

A callback triggered after the request is called success

#
protected callable $error

A callback triggered when the request fails

A callback triggered when the request fails

The $textStatus could be curl, http, and parser

#
protected callable $complete

A callback triggered when request finishes (after success and error callbacks are executed)

A callback triggered when request finishes (after success and error callbacks are executed)

#
protected array $curlOptions

The user define options for cURL handle

The user define options for cURL handle

# array()
protected array $defaultCurlOptions

The predefined options for cURL handle

The predefined options for cURL handle

# array( CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, )
protected boolean $result

The request result

The request result

#
protected string $responseText

The response body string

The response body string

#
protected mixed $response

The parsed response data

The parsed response data

#
protected string $responseHeader

The response header string

The response header string

#
protected string $responseHeaders

The parsed response header array

The parsed response header array

#
protected array $responseCookies

A key-value array contains the response cookies

A key-value array contains the response cookies

#
protected resource $ch

The cURL session

The cURL session

#
protected string $errorStatus

The error text status

The error text status

# ''
protected ErrorException $errorException

The error exception object

The error exception object

#
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen