Swoole-1.8.0版本增加了对异步Http/WebSocket
客户端的支持。底层是用纯C编写,拥有超高的性能。
--enable-async-httpclient
来开启此功能。Http-Chunk
、Keep-Alive
、form-data
HTTP/1.1
gzip
压缩格式支持需要依赖zlib
库function swoole_http_client->__construct(string $ip, int port, bool $ssl = false);
swoole_async_dns_lookup
查询域名对应的IP地址http
为80
,https
为443
SSL/TLS
隧道加密,如果目标服务器是https
必须设置$ssl
参数为true
$body
请求响应后服务器端返回的内容$statusCode
服务器端返回的Http状态码,如404
、200
、500
等$set_cookie_headers
服务器端返回的原始COOKIE
信息,包括了domain
和path
项$headers
Http请求头$cookies
Http Cookie某些情况下服务器端没有正常返回数据,底层会将$statusCode
标记为负数。
-1
:连接超时,服务器未监听端口或网络丢失,可以读取$errCode
获取具体的网络错误码-2
:请求超时,服务器未在规定的timeout
时间内返回response
-3
:客户端请求发出后,服务器强制切断连接