Welcome to the Cookbook

loading...

8.8.2 post

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

More information about translations

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

string function post ($uri, $data, $request)

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

App::import('Core', 'HttpSocket');
$HttpSocket = new HttpSocket();
$results = $HttpSocket->post('www.somesite.com/add', array('name' => 'test', 'type' => 'user');  
//$results には post の結果が格納されます
  1. App::import('Core', 'HttpSocket');
  2. $HttpSocket = new HttpSocket();
  3. $results = $HttpSocket->post('www.somesite.com/add', array('name' => 'test', 'type' => 'user');
  4. //$results には post の結果が格納されます