Properties

$url

$url : string

需要请求的Url地址

Type

string

$content

$content : mixed

发送内容,可以是字符串、数组(支持键值、Yurun\Util\YurunHttp\Http\Psr7\UploadedFile,其中键值会作为html编码,文件则是上传)

Type

mixed

$options

$options : array

`curl_setopt_array()`所需要的第二个参数

Type

array

$headers

$headers : array

请求头

Type

array

$cookies

$cookies : array

Cookies

Type

array

$retry

$retry : integer

失败重试次数,默认为0

Type

integer

$useProxy

$useProxy : boolean

是否使用代理,默认false

Type

boolean

$proxy

$proxy : array

代理设置

Type

array

$isVerifyCA

$isVerifyCA : boolean

是否验证证书

Type

boolean

$caCert

$caCert : string

CA根证书路径

Type

string

$connectTimeout

$connectTimeout : integer

连接超时时间,单位:毫秒

Type

integer

$timeout

$timeout : integer

总超时时间,单位:毫秒

Type

integer

$downloadSpeed

$downloadSpeed : integer

下载限速,为0则不限制,单位:字节

Type

integer

$uploadSpeed

$uploadSpeed : integer

上传限速,为0则不限制,单位:字节

Type

integer

$username

$username : string

用于连接中需要的用户名

Type

string

$password

$password : string

用于连接中需要的密码

Type

string

$saveFileOption

$saveFileOption : mixed

请求结果保存至文件的配置

Type

mixed

$followLocation

$followLocation : boolean

是否启用重定向

Type

boolean

$maxRedirects

$maxRedirects : integer

最大重定向次数

Type

integer

$certType

$certType : string

证书类型 支持的格式有"PEM" (默认值), "DER"和"ENG"

Type

string

$certPath

$certPath : string

一个包含 PEM 格式证书的文件名

Type

string

$certPassword

$certPassword : string

使用证书需要的密码

Type

string

$keyType

$keyType : string

certType规定的私钥的加密类型,支持的密钥类型为"PEM"(默认值)、"DER"和"ENG"

Type

string

$keyPath

$keyPath : string

包含 SSL 私钥的文件名

Type

string

$keyPassword

$keyPassword : string

SSL私钥的密码

Type

string

$method

$method : string

请求方法

Type

string

$protocolVersion

$protocolVersion : string

Http 协议版本

Type

string

$proxyAuths

$proxyAuths : 

代理认证方式

Type

$proxyType

$proxyType : 

代理类型

Type

Methods

__construct()

__construct() : mixed

构造方法

Returns

mixed

__destruct()

__destruct() 

析构方法

open()

open() : void

打开一个新连接,初始化所有参数。一般不需要手动调用。

close()

close() : void

关闭连接。一般不需要手动调用。

newSession()

newSession() : static

创建一个新会话,等同于new

Returns

static

url()

url(string  $url) : static

设置请求地址

Parameters

string $url

请求地址

Returns

static

content()

content(mixed  $content) : static

设置发送内容,requestBody的别名

Parameters

mixed $content

发送内容,可以是字符串、数组

Returns

static

params()

params(mixed  $params) : static

设置参数,requestBody的别名

Parameters

mixed $params

发送内容,可以是字符串、数组

Returns

static

requestBody()

requestBody(mixed  $requestBody) : static

设置请求主体

Parameters

mixed $requestBody

发送内容,可以是字符串、数组

Returns

static

options()

options(array  $options) : static

批量设置CURL的Option

Parameters

array $options

curl_setopt_array()所需要的第二个参数

Returns

static

option()

option(integer  $option, mixed  $value) : static

设置CURL的Option

Parameters

integer $option

需要设置的CURLOPT_XXX选项

mixed $value

Returns

static

headers()

headers(array  $headers) : static

批量设置请求头

Parameters

array $headers

Returns

static

header()

header(string  $header, string  $value) : static

设置请求头

Parameters

string $header

请求头名称

string $value

Returns

static

accept()

accept(string  $accept) : static

设置Accept

Parameters

string $accept

Returns

static

acceptLanguage()

acceptLanguage(string  $acceptLanguage) : static

设置Accept-Language

Parameters

string $acceptLanguage

Returns

static

acceptEncoding()

acceptEncoding(string  $acceptEncoding) : static

设置Accept-Encoding

Parameters

string $acceptEncoding

Returns

static

acceptRanges()

acceptRanges(string  $acceptRanges) : static

设置Accept-Ranges

Parameters

string $acceptRanges

Returns

static

cacheControl()

cacheControl(string  $cacheControl) : static

设置Cache-Control

Parameters

string $cacheControl

Returns

static

cookies()

cookies(array  $cookies) : static

批量设置Cookies

Parameters

array $cookies

键值对应数组

Returns

static

cookie()

cookie(string  $name, string  $value) : static

设置Cookie

Parameters

string $name

名称

string $value

Returns

static

contentType()

contentType(string  $contentType) : static

设置Content-Type

Parameters

string $contentType

Returns

static

range()

range(string  $range) : static

设置Range

Parameters

string $range

Returns

static

referer()

referer(string  $referer) : static

设置Referer

Parameters

string $referer

Returns

static

userAgent()

userAgent(string  $userAgent) : static

设置User-Agent

Parameters

string $userAgent

Returns

static

ua()

ua(string  $userAgent) : static

设置User-Agent,userAgent的别名

Parameters

string $userAgent

Returns

static

retry()

retry(string  $retry) : static

设置失败重试次数,状态码为5XX或者0才需要重试

Parameters

string $retry

Returns

static

proxy()

proxy(string  $server, integer  $port, string  $type = 'http', string  $auth = 'basic') : static

代理

Parameters

string $server

代理服务器地址

integer $port

代理服务器端口

string $type

代理类型,支持:http、socks4、socks4a、socks5

string $auth

代理认证方式,支持:basic、ntlm。一般默认basic

Returns

static

proxyAuth()

proxyAuth(string  $username, string  $password) : static

代理认证

Parameters

string $username
string $password

Returns

static

timeout()

timeout(integer  $timeout = null, integer  $connectTimeout = null) : static

设置超时时间

Parameters

integer $timeout

总超时时间,单位:毫秒

integer $connectTimeout

连接超时时间,单位:毫秒

Returns

static

limitRate()

limitRate(integer  $download, integer  $upload) : static

限速

Parameters

integer $download

下载速度,为0则不限制,单位:字节

integer $upload

上传速度,为0则不限制,单位:字节

Returns

static

userPwd()

userPwd(string  $username, string  $password) : static

设置用于连接中需要的用户名和密码

Parameters

string $username

用户名

string $password

密码

Returns

static

saveFile()

saveFile(string  $filePath, string  $fileMode = 'w+') : static

保存至文件的设置

Parameters

string $filePath

文件路径

string $fileMode

文件打开方式,默认w+

Returns

static

getSavePath()

getSavePath() : string

获取文件保存路径

Returns

string

sslCert()

sslCert(string  $path, string  $type = null, string  $password = null) : static

设置SSL证书

Parameters

string $path

一个包含 PEM 格式证书的文件名

string $type

证书类型,支持的格式有”PEM”(默认值),“DER”和”ENG”

string $password

使用证书需要的密码

Returns

static

sslKey()

sslKey(string  $path, string  $type = null, string  $password = null) : static

设置SSL私钥

Parameters

string $path

包含 SSL 私钥的文件名

string $type

certType规定的私钥的加密类型,支持的密钥类型为”PEM”(默认值)、”DER”和”ENG”

string $password

SSL私钥的密码

Returns

static

method()

method(string  $method) : static

设置请求方法

Parameters

string $method

Returns

static

buildRequest()

buildRequest(string  $url = null, array  $requestBody = null, string|null  $method = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Request

构建请求类

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $method

请求方法,GET、POST等

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Request

send()

send(string  $url = null, array  $requestBody = null, string|null  $method = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

发送请求,所有请求的老祖宗

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $method

请求方法,GET、POST等

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

sendHttp2WithoutRecv()

sendHttp2WithoutRecv(string  $url = null, array  $requestBody = null, array  $method = 'GET', string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

发送 Http2 请求不调用 recv()

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

array $method

请求方法,GET、POST等

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

get()

get(string  $url = null, array  $requestBody = null) : \Yurun\Util\YurunHttp\Http\Response

GET请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

Returns

\Yurun\Util\YurunHttp\Http\Response

post()

post(string  $url = null, array  $requestBody = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

POST请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

head()

head(string  $url = null, array  $requestBody = null) : \Yurun\Util\YurunHttp\Http\Response

HEAD请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

Returns

\Yurun\Util\YurunHttp\Http\Response

put()

put(string  $url = null, array  $requestBody = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

PUT请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

patch()

patch(string  $url = null, array  $requestBody = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

PATCH请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

delete()

delete(string  $url = null, array  $requestBody = null, string|null  $contentType = null) : \Yurun\Util\YurunHttp\Http\Response

DELETE请求

Parameters

string $url

请求地址,如果为null则取url属性值

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

\Yurun\Util\YurunHttp\Http\Response

download()

download(string  $fileName, string  $url = null, array  $requestBody = null, string  $method = 'GET') : \Yurun\Util\YurunHttp\Http\Response

直接下载文件

Parameters

string $fileName

保存路径,如果以 .* 结尾,则根据 Content-Type 自动决定扩展名

string $url

下载文件地址

array $requestBody

发送内容,可以是字符串、数组,如果为空则取content属性值

string $method

请求方法,GET、POST等,一般用GET

Returns

\Yurun\Util\YurunHttp\Http\Response

parseRequestBody()

parseRequestBody(string|array  $requestBody, string|null  $contentType) : array

处理请求主体

Parameters

string|array $requestBody
string|null $contentType

内容类型,支持null/json,为null时不处理

Returns

array