HTTP 客户端扩展 2.0.1 版发布了
2016-08-04
3526次浏览
我们很高兴的宣布 HTTP 客户端扩展 2.0.1 版发布了,其中包含 10 个功能增强和 bug 的修复。详情请参阅 CHANGELOG。此次最大的改进是在 HTTP 请求时加入了 beforeSend
和 afterSend
监听事件:
use yii\httpclient\Client;
use yii\httpclient\Request;
use yii\httpclient\RequestEvent;
$client = new Client();
$request = $client->createRequest()
->setMethod('get')
->setUrl('http://api.domain.com')
->setData(['param' => 'value']);
// Ensure signature generation based on final data set:
$request->on(Request::EVENT_BEFORE_SEND, function (RequestEvent $event) {
$data = $event->request->getData();
$signature = md5(http_build_query($data));
$data['signature'] = $signature;
$event->request->setData($data);
});
// Normalize response data:
$request->on(Request::EVENT_AFTER_SEND, function (RequestEvent $event) {
$data = $event->response->getData();
$data['content'] = base64_decode($data['encoded_content']);
$event->response->setData($data);
});
$response = $request->send();
请参考文档了解更多。
新闻归档
热门标签
- yii3
- 扩展
- 发布
- yii2
- debug
- auth client
- view
- bootstrap
- release
- html
- redis
- apidoc
- Yii 2.0
- Yii 1.1
- mongodb
- mailer
- extensions
- twig
- gii
- queue
- runner
- http 客户端
- console
- validation
- cache
- sphinx
- widget
- hydrator
- translator
- symfonymailer
- db
- http
- log
- error handler
- config
- swiftmailer
- 图书
- imagine
- assets
- i18n
- IDE
- swagger
- elasticsearch
- router
- csrf
- smarty
- definitions
- logging
- fastroute
- user