属性 |
值 |
命名空间 |
fize\net |
类名 |
Http |
初始化
public function __construct (
string $cookie_dir = null,
int $time_out = 30,
int $retries = 1
)
参数: |
名称
|
说明
|
cookie_dir
|
指定保存COOKIE文件的路径,默认null表示不使用COOKIE
|
time_out
|
设定超时时间,默认30秒
|
retries
|
curl重试次数
|
|
获取最后的错误代码
public function getLastErrCode () : int
获取最后的错误描述
public function getLastErrMsg () : string
获取最后的信息列表
public function getLastInfo () : array
获取最后的HTTP状态码
public function getHttpCode () : int
返回最后的响应内容
public function getResponse () : string
getResponseHeaders()
返回最后的响应头
public function getResponseHeaders (
$key = null
) : mixed
参数: |
名称
|
说明
|
key
|
string 如果传入该值则返回该响应头键值
|
|
返回最后的响应主体内容
public function getResponseBody () : string
addRequestHeader()
添加请求头
public function addRequestHeader (
string $key,
mixed $value
)
addRequestHeaders()
批量添加请求头
public function addRequestHeaders (
array $headers
)
添加CURL选项
public function addOption (
mixed $key,
mixed $value
)
批量添加CURL选项
public function addOptions (
array $options
)
为下一次HTTP请求做准备
底层发起 HTTP 请求
public function send (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : mixed
参数: |
名称
|
说明
|
url
|
指定URL
|
headers
|
设置请求头
|
opts
|
设置CURL选项
|
domain_empty
|
指明该链接是否是无主域链接
|
|
返回值: | 成功时返回主体内容,失败时返回false
|
GET 请求
public static function get (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
附加的文件头
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
如果有GET参数需要附加请自行构建最终URL
POST 请求
public static function post (
string $url,
mixed $data,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
data
|
可以是数组(推荐)或者请求字符串。
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
OPTIONS 请求
public static function options (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
HEAD 请求
public static function head (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
DELETE 请求
public static function delete (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
PATCH 请求
public static function patch (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
PUT 请求
public static function put (
string $url,
mixed $data = "",
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
data
|
可以是数组(推荐)或者请求字符串。
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
TRACE 请求
public static function trace (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
MOVE 请求
public static function move (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
COPY 请求
public static function copy (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
LINK 请求
public static function link (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
UNLINK 请求
public static function unlink (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|
WRAPPED 请求
public static function wrapped (
string $url,
array $headers = [],
array $opts = [],
bool $domain_empty = false
) : string
参数: |
名称
|
说明
|
url
|
指定链接
|
headers
|
设定请求头设置
|
opts
|
参数配置数组
|
domain_empty
|
该链接是否是无主域链接
|
|
返回值: | 返回响应内容,失败是返回false
|