guzzle是一个php http 客户端和框架,用于构建 restful web service 客户端。all the power of curl with a simple interface.持久连接和并行请求streams request and response bodiesservice descriptions for quickly building clients.powered by the symfony2 eventdispatcher.use all of the code or only specific components.plugins for caching, logging, oauth, mocks, and moreincludes a custom node.js webserver to test your clients.
get('/user')->setauth('user', 'pass');// send the request and get the response$response = $request->send();echo $response->getbody();// >>> {type:user, ...echo $response->getheader('content-length');// >>> 792// create a client to work with the twitter api$client = new client('https://api.twitter.com/{version}', array( 'version' => '1.1'));// sign all requests with the oauthplugin$client->addsubscriber(new guzzle\plugin\oauth\oauthplugin(array( 'consumer_key' => '***', 'consumer_secret' => '***', 'token' => '***', 'token_secret' => '***')));echo $client->get('statuses/user_timeline.json')->send()->getbody();// >>> {public_gists:6,type:user ...// create a tweet using post$request = $client->post('statuses/update.json', null, array( 'status' => 'tweeted with guzzle, http://guzzlephp.org'));// send the request and parse the json response into an array$data = $request->send()->json();echo $data['text'];// >>> tweeted with guzzle, http://t.co/kngjmfrk
复制代码
项目主页:http://www.open-open.com/lib/view/home/1392714245460