PHP Класс HttpRequestService, thinksns

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$_encode default is json
$api_url #Set up the API root URL.
$connecttimeout #Set connect timeout.
$decodeFormat Only support json & xml for extension
$format #Response format.
$http_code #Contains the last HTTP status code returned.
$http_header
$http_info #Contains the last HTTP headers returned.
$ssl_verifypeer #Verify SSL Cert.
$timeout #Set timeout default.

Открытые методы

Метод Описание
_DELETE ( $url, $params = null, $username = null, $password = null ) : RESTClient DELETE wrapper for delete data
_GET ( $url, $params = null, $username = null, $password = null ) : RESTClient GET wrapper for get data
_POST ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient POST wrapper for insert data
_POST_FOPEN ( $url, $params = null, $username = null, $password = null, $contentType = null )
_PUT ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient PUT wrapper for update data
__construct ( )
_photoUpload ( $url, $postdata, $files )
call ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null ) : RESTClient Execute calls
call_fopen ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null )
close ( ) Closes the connection and release resources
convertEncoding ( $source, $in, $out )
create_post_body ( $post_params )
do_post_request ( $url, $postdata, $files ) : mixed POST wrapper,不基于curl函数,环境可以不支持curl函数
getHeader ( $ch, $header ) Get the header info to store.
get_http_url ( ) parses the url and rebuilds it to be scheme://host/path
json_foreach ( $jsonArr ) 将stdclass object转换成数组,并转换编码
objectToArray ( $obj )
parseResponse ( $resp, $ext = '' ) * Parse response, including json, xml, plain text
setAuthorizeInfo ( $username, $password ) Set the authorize info for Basic Authentication
setContentType ( string $contentType ) Set the Content-Type of the request to be send Format like "application/json" or "application/xml" or "text/plain" or other
setDecodeFormat ( $format = null ) : boolean Sets the format type to be decoded
setEncode ( $encode )
setFormat ( $format = null ) : boolean Sets the format type to be extension
setMethod ( $method ) Set the Request HTTP Method
setNotFollow ( ) : RESTClient Settings that won't follow redirects
setParameters ( $params ) Set Parameters to be send on the request It can be both a key/value par array (as in array("key"=>"value")) or a string containing the body of the request, like a XML, JSON or other Proper content-type should be set for the body if not a array
setURL ( $url ) Sets the URL to be Called
to_postdata ( ) builds the data one would send in a POST request
to_url ( ) builds a url usable for a GET request
xml_decode ( $data, $toArray = false ) * XML decode

Описание методов

_DELETE() публичный Метод

DELETE wrapper for delete data
public _DELETE ( $url, $params = null, $username = null, $password = null ) : RESTClient
$url String
$params mixed
$username String
$password String
Результат RESTClient

_GET() публичный Метод

GET wrapper for get data
public _GET ( $url, $params = null, $username = null, $password = null ) : RESTClient
$url String
$params mixed
$username String
$password String
Результат RESTClient

_POST() публичный Метод

POST wrapper for insert data
public _POST ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$params mixed
$username String
$password String
$contentType String
Результат RESTClient

_POST_FOPEN() публичный Метод

public _POST_FOPEN ( $url, $params = null, $username = null, $password = null, $contentType = null )

_PUT() публичный Метод

PUT wrapper for update data
public _PUT ( $url, $params = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$params mixed
$username String
$password String
$contentType String
Результат RESTClient

__construct() публичный Метод

public __construct ( )

_photoUpload() публичный Метод

public _photoUpload ( $url, $postdata, $files )

call() публичный Метод

Execute calls
public call ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null ) : RESTClient
$url String
$method String
$postFields String
$username String
$password String
$contentType String
Результат RESTClient

call_fopen() публичный Метод

public call_fopen ( $url, $method, $postFields = null, $username = null, $password = null, $contentType = null )

close() публичный Метод

Closes the connection and release resources
public close ( )

convertEncoding() публичный статический Метод

public static convertEncoding ( $source, $in, $out )

create_post_body() публичный Метод

public create_post_body ( $post_params )

do_post_request() публичный Метод

POST wrapper,不基于curl函数,环境可以不支持curl函数
public do_post_request ( $url, $postdata, $files ) : mixed
Результат mixed

getHeader() публичный Метод

Get the header info to store.
public getHeader ( $ch, $header )

get_http_url() публичный Метод

parses the url and rebuilds it to be scheme://host/path
public get_http_url ( )

json_foreach() публичный Метод

将stdclass object转换成数组,并转换编码
public json_foreach ( $jsonArr )

objectToArray() публичный статический Метод

public static objectToArray ( $obj )

parseResponse() публичный Метод

* Parse response, including json, xml, plain text
public parseResponse ( $resp, $ext = '' )
$resp String
$ext String, including json/xml

setAuthorizeInfo() публичный Метод

Set the authorize info for Basic Authentication
public setAuthorizeInfo ( $username, $password )
$username String
$password String

setContentType() публичный Метод

Set the Content-Type of the request to be send Format like "application/json" or "application/xml" or "text/plain" or other
public setContentType ( string $contentType )
$contentType string

setDecodeFormat() публичный Метод

Sets the format type to be decoded
public setDecodeFormat ( $format = null ) : boolean
$format String
Результат boolean

setEncode() публичный Метод

public setEncode ( $encode )

setFormat() публичный Метод

Sets the format type to be extension
public setFormat ( $format = null ) : boolean
$format String
Результат boolean

setMethod() публичный Метод

Set the Request HTTP Method
public setMethod ( $method )
$method String

setNotFollow() публичный Метод

Settings that won't follow redirects
public setNotFollow ( ) : RESTClient
Результат RESTClient

setParameters() публичный Метод

Set Parameters to be send on the request It can be both a key/value par array (as in array("key"=>"value")) or a string containing the body of the request, like a XML, JSON or other Proper content-type should be set for the body if not a array
public setParameters ( $params )
$params mixed

setURL() публичный Метод

Sets the URL to be Called
public setURL ( $url )
$url String

to_postdata() публичный Метод

builds the data one would send in a POST request
public to_postdata ( )

to_url() публичный Метод

builds a url usable for a GET request
public to_url ( )

xml_decode() публичный статический Метод

* XML decode
public static xml_decode ( $data, $toArray = false )
$data String
$toArray boolean, true for make it be array

Описание свойств

$_encode публичное свойство

default is json
public $_encode

$api_url публичное свойство

#Set up the API root URL.
public $api_url

$connecttimeout публичное свойство

#Set connect timeout.
public $connecttimeout

$decodeFormat публичное свойство

Only support json & xml for extension
public $decodeFormat

$format публичное свойство

#Response format.
public $format

$http_code публичное свойство

#Contains the last HTTP status code returned.
public $http_code

$http_header публичное свойство

public $http_header

$http_info публичное свойство

#Contains the last HTTP headers returned.
public $http_info

$ssl_verifypeer публичное свойство

#Verify SSL Cert.
public $ssl_verifypeer

$timeout публичное свойство

#Set timeout default.
public $timeout