get 请求
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
use Guzzle\Http\Client;
$client = new Client('http://www.xxxxxx.com');
$header = array('uuid' => 1, 'version' => "3.0", "Accept" => "application/json");
$request = $client->get("/accounts/checkName?name=jack", $header);
$response = $request->send();
$body = $response->getBody(true);
echo $body;
post 请求
<?php
require dirname(__FILE__) . '/../vendor/autoload.php';
use Guzzle\Http\Client;
$client = new Client('http://www.xxxx.com');
$header = array('uuid' => 1, 'version' => "3.0", "Accept" => "application/json","Content-Type"=>"application/x-www-form-urlencoded","deviceType"=>"IOS");
$postBody = array(
'email'=> 'walker@xxx.com',
'password'=> 'xxxxx'
);
$request = $client->post("/sessions", $header,$postBody);
$response = $request->send();
$body = $response->getBody(true);
echo $body;
|