Download the PHP package easyswoole/http-client without Composer

On this page you can find all versions of the php package easyswoole/http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package http-client

EasySwoole HTTP Client

基于 Swoole\Coroutine\Http\Client 的轻量级协程 HTTP/WebSocket 客户端,支持常见 HTTP 方法、文件上传与下载、Cookie、代理、TLS 和重定向。

环境要求

安装

快速开始

发起请求

GET 与查询参数

setQuery() 会合并已有查询参数,新值优先:

POST、PUT、PATCH 与 OPTIONS

get()、head()、trace() 和 delete() 的第一个参数是本次请求要合并的 Header;put()、post()、patch() 和 options() 的第一个参数是请求体,第二个参数是 Header。

JSON 与 XML

postJson() 和 postXml() 接收已经编码好的字符串,并自动设置对应的 Content-Type:

Header、Cookie 与认证

Header 名称会按 HTTP 规则进行大小写归一化,Header 值会保持原样。发生跨 origin 重定向(协议、主机或端口变化)时,客户端会移除 Authorization、Proxy-Authorization 和 Cookie,避免凭证泄漏。

文件上传

兼容 PHP 原生 CURLFile,也可以使用本库提供的文件对象:

本库 CURLFile 的构造参数依次为:本地路径、表单字段名、可选 MIME 类型。可通过 setFilename()、setOffset() 和 setLength() 进一步控制上传信息。

文件下载

download() 直接把响应体写入文件,适合大文件下载;成功时返回 Response,连接或写入失败时返回 false。

下载请求同样支持 Cookie、Header 和重定向。

重定向

默认最多跟随 3 次重定向,支持 301、302、303、307 和 308:

重定向行为:

超时与长连接

也可以直接设置 Swoole 客户端参数:

TLS

还可以使用 setSslCapath() 设置 CA 目录,或通过 setEnableSSL(true) 强制启用 TLS。

代理与本地绑定

WebSocket

响应处理

网络错误通常表现为非正常状态码(例如 -1),可结合 getErrCode() 和 getErrMsg() 判断具体原因。JSON/XML 解码失败时,相应解析方法会返回 null 或 false。

测试

测试 bootstrap 会自动启动本地 HTTP 和 WebSocket mock 服务,并在测试结束后关闭由它创建的进程。测试覆盖普通请求、文件上传/下载、Cookie、认证、请求复用、WebSocket 以及各种重定向行为。

代理测试默认跳过。如需运行,配置以下环境变量:

主要 API

分类 方法
URL setUrl()、setPath()、setQuery()、setEnableSSL()
请求 get()、head()、trace()、delete()、put()、post()、patch()、options()、postJson()、postXml()
Header/Cookie setHeader()、setHeaders()、setCookies()、addCookie()、addCookies()、setBasicAuth()
内容类型 setContentType()、setContentTypeJson()、setContentTypeXml()、setContentTypeFormData()、setContentTypeFormUrlencoded()、setXMLHttpRequest()
重定向 setFollowLocation()、enableFollowLocation()
超时/连接 setTimeout()、setConnectTimeout()、setReadTimeout()、setWriteTimeout()、setKeepAlive()
TLS setSslVerifyPeer()、setSslHostName()、setSslCafile()、setSslCapath()、setSslCertFile()、setSslKeyFile()、setSslPassphrase()
代理/网络 setProxyHttp()、setProxySocks5()、setSocketBind()
下载 download()
WebSocket upgrade()、push()、recv()
底层配置 setClientSetting()、setClientSettings()、getClient()

License

Apache-2.0


All versions of http-client with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
easyswoole/spl Version ^2.0
ext-curl Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package easyswoole/http-client contains the following files

Loading the files please wait ...