内容纲要

[code]
composer require guzzlehttp/guzzle:~6.0
[/code]

[code language=”php”]
$client = new \GuzzleHttp\Client();

// Create a request
$request = $client->get(‘example.com’);
// Get the actual response without headers
$response = $request->getBody();
return $response;
[/code]

[code language=”php”]
$client = new \GuzzleHttp\Client();
// Create a request with auth credentials
$request = $client->get(‘https://api.github.com/user’,[‘auth’=>[‘username’,’password’]]);
// Get the actual response without headers
$response = $request->getBody();
return $response;
[/code]

[code language=”php”]
$client = new \GuzzleHttp\Client();
$body[‘name’] = "Testing";
$url = "http://my-domain.com/api/v1/post";
$response = $client->createRequest("POST", $url, [‘body’=>$body]);
$response = $client->send($response);
return $response;
[/code]

[code]
GET: $client->get(‘http://my-domain.com/get’, [/** options **/])
POST: $client->post(‘http://my-domain.com/post’, [/** options **/])
HEAD: $client->head(‘http://my-domain.com/get’, [/** options **/])
PUT: $client->put(‘http://my-domain.com/put’, [/** options **/])
DELETE: $client->delete(‘http://my-domain.com/delete’, [/** options **/])
OPTIONS: $client->options(‘http://my-domain.com/get’, [/** options **/])
PATCH: $client->patch(‘http://my-domain.com/put’, [/** options **/])
[/code]

发表评论

电子邮件地址不会被公开。 必填项已用*标注