Welcome to the Cookbook

loading...

8.8.1 get

The original text for this section has changed since it was translated. Please help resolve this difference. You can:

More information about translations

get メソッドはシンプルな HTTP GET のリクエストを作成し、リクエストの結果を返します。

string function get ($uri, $query, $request)

$uri はリクエストを行うウェブアドレス、$query はクエリ文字列のパラメータです。クエリは、文字列で "param1=foo&param2=bar" としても、キー付きの配列で配列で array('param1' => 'foo', 'param2' => 'bar') というようにしても、どちらでもかまいません。

App::import('Core', 'HttpSocket');
$HttpSocket = new HttpSocket();
$results = $HttpSocket->get('www.google.com/search', 'q=cakephp');  
//Google で "cakephp" を検索した結果の HTML が返ります
  1. App::import('Core', 'HttpSocket');
  2. $HttpSocket = new HttpSocket();
  3. $results = $HttpSocket->get('www.google.com/search', 'q=cakephp');
  4. //Google で "cakephp" を検索した結果の HTML が返ります