xp-framework / http
为 XP 框架提供 HTTP 协议支持
v10.3.0
2024-03-24 11:57 UTC
Requires
- php: >=7.0.0
- xp-framework/core: ^12.0 | ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/logging: ^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.5
- xp-framework/networking: ^10.0 | ^9.0 | ^8.0 | ^7.0 | ^6.6
Requires (Dev)
- xp-framework/test: ^2.0 | ^1.0
Suggests
- ext-curl: Alternative to ext-openssl for SSL-/TLS connections
- ext-openssl: Allows to use SSL/TLS, e.g. for https-connections
- dev-master
- v10.3.0
- v10.2.0
- v10.1.0
- v10.0.3
- v10.0.2
- v10.0.1
- v10.0.0
- v9.1.4
- v9.1.3
- v9.1.2
- v9.1.1
- v9.1.0
- v9.0.3
- v9.0.2
- v9.0.1
- v9.0.0
- v8.0.1
- v8.0.0
- v7.0.1
- v7.0.0
- v6.2.1
- v6.2.0
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1.0
- v6.0.1
- v6.0.0
- dev-feature/keep-alive
- dev-feature/accept-paths
- dev-fix/http-delete
- dev-feature/digest-auth-squash
- dev-feature/digest-auth
This package is auto-updated.
Last update: 2024-08-24 12:53:27 UTC
README
实现了 HTTP(超文本传输协议)并提供了一个客户端与 HTTP 服务器交互。`HttpConnection` 类是入口点类。
方法
不同的请求方法由 `HttpConnection` 类方法如下处理
- GET - 通过 `get()` 方法
- POST - 通过 `post()` 方法
- HEAD - 通过 `head()` 方法
- PUT - 通过 `put()` 方法
- PATCH - 通过 `patch()` 方法
- DELETE - 通过 `delete()` 方法
- OPTIONS - 通过 `options()` 方法
- TRACE - 通过 `trace()` 方法
其他方法(例如 WebDAV 中的 `MKCOL`)通过 `request()` 方法支持。
头部信息
以下代码将显示 HEAD 请求的响应头部信息
use peer\http\HttpConnection; $c= new HttpConnection('http://xp-framework.net/'); Console::writeLine($c->head());
获取数据
with ($c= new HttpConnection('http://xp-framework.net/')); { $response= $c->get(); Console::writeLine('Response: ', $response); $in= $response->in(); while ($in->available()) { $bytes= $in->read(); } }
SSL 支持
此 API 还支持 SSL 连接 - 根据 `HttpConnection` 构造函数中提供的方案,`HttpRequestFactory` 类将创建 SSL 连接。对外面是透明的,其余的调用都是一样的!
示例
$c= new HttpConnection('https://example.com/');
注意:SSL 连接依赖于 PHP 扩展 `curl` 或 `openssl`。