quibax/http

基于 vinelab/http 改编,根据自身需求进行了一些调整。

维护者

详细信息

github.com/QuibaX/http

源代码

安装: 229

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 30

v1.2.0 2015-02-26 17:08 UTC

This package is auto-updated.

Last update: 2024-08-29 04:19:48 UTC


README

build status

Dependency Status

SensioLabsInsight

http://客户端

一个智能简单的HTTP客户端,用于发送和接收JSON和XML。

安装

Composer

// 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());

Laravel

编辑 app.php 并将 'Vinelab\Http\HttpServiceProvider', 添加到 'providers' 数组中。

它将自动别名自己为 HttpClient,因此无需在 app.php 中进行别名设置,除非您想进行自定义 - 在这种情况下,编辑您的 'aliases'app.php 中添加 'MyHttp' => 'Vinelab\Http\Facades\Client',

用法

GET

简单

	$response = HttpClient::get('http://example.org');

	// raw content
	$response->content();

带参数

	$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();

头部

$response = HttpClient::get([
	'url' => 'http://some.where.url',
	'headers' => ['Connection: close', 'Authorization: some-secret-here']
]);

// The full headers payload
$response->headers();

强制HTTP版本

HttpClient::get(['version' => 1.1, 'url' => 'http://some.url']);

原始内容

HttpClient::post(['url' => 'http://to.send.to', 'content' => 'Whatever content here may go!']);

自定义查询字符串

传递给 content 键的内容将被连接到 URL 后面,并跟一个 ?

HttpClient::get(['url' => 'http://my.url', 'content' => 'a=b&c=d']);

这与不同的HTTP动词的过程非常相似。支持 GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD

待办事项

  • 改进测试,包括测试所有响应方法(如statusCode...)
  • 包括处理错误数据的测试
  • 改进测试,包括测试所有HTTP动词