在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Vinelab/http开源软件地址:https://github.com/Vinelab/http开源编程语言:PHP 100.0%开源软件介绍:http://ClientA smart, simple and fault-tolerant HTTP client for sending and recieving JSON and XML. InstallationComposer
// change this to point correctly according
// to your folder structure.
require './vendor/autoload.php';
use Vinelab\Http\Client as HttpClient;
$client = new HttpClient;
$response = $client->get('echo.jsontest.com/key/value/something/here');
var_dump($response->json()); LaravelEdit app.php and add It will automatically alias itself as HttpClient so no need to alias it in your app.php, unless you would like to customize it - in that case edit your 'aliases' in app.php adding UsageGETSimple$response = HttpClient::get('http://example.org');
// raw content
$response->content(); With Params$request = [
'url' => 'http://somehost.net/something',
'params' => [
'id' => '12350ME1D',
'lang' => 'en-us',
'format' => 'rss_200'
]
];
$response = HttpClient::get($request);
// raw content
$response->content();
// in case of json
$response->json();
// XML
$response->xml(); POST$request = [
'url' => 'http://somehost.net/somewhere',
'params' => [
'id' => '12350ME1D',
'lang' => 'en-us',
'format' => 'rss_200'
]
];
$response = HttpClient::post($request);
// raw content
$response->content();
// in case of json
$response->json();
// XML
$response->xml(); OptionsThese options work with all requests. TimeoutYou can set the $request = [
'url' => 'http://somehost.net/somewhere',
'params' => [
'id' => '12350ME1D',
'lang' => 'en-us',
'format' => 'rss_200'
],
'timeout' => 10
]; Headers$response = HttpClient::get([
'url' => 'http://somehost.net/somewhere',
'headers' => ['Connection: close', 'Authorization: some-secret-here']
]);
// The full headers payload
$response->headers(); Basic Auth$response = HttpClient::get([
'url' => 'http://somehost.net/somewhere',
'auth' => [
'username' => 'user',
'password' => 'pass'
],
'params' => [
'var1' => 'value1',
'var2' => 'value2'
]
]); Digest Auth$response = HttpClient::get([
'url' => 'http://some.where.url',
'digest' => [
'username' => 'user',
'password' => 'pass'
],
'params' => [
'var1' => 'value1',
'var2' => 'value2'
]
]); Enforce HTTP VersionHttpClient::get(['version' => 1.1, 'url' => 'http://some.url']); Raw ContentHttpClient::post(['url' => 'http://to.send.to', 'content' => 'Whatever content here may go!']); Custom Query StringThe content passed in the HttpClient::get(['url' => 'http://my.url', 'content' => 'a=b&c=d']);
Fault ToleranceFault tolerance allows the request to be re-issued when it fails (i.e. timeout). This is useful in cases such as Microservices: When a service is down and is being called by another service, with fault tolerance the request will be re-issued in the hopes of the destination service being up again. Issue a fault-tolerant request by setting the $request = [
'url' => 'http://somehost.net/somewhere',
'params' => [
'id' => '12350ME1D',
'lang' => 'en-us',
'format' => 'rss_200'
],
'timeout' => 10
'tolerant' => true,
'timeUntilNextTry' => 1,
'triesUntilFailure' => 3
]; In case of timeout occurance, a
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论