HTTP 请求客户端(HTTP Request Client)

通过 Phalcon\Http\Client 我们可以发起 HTTP 请求。

GET 请求(GET Request)

  1. <?php
  2.  
  3. use Phalcon\Http\Client\Adapter\Curl as Client;
  4.  
  5. // Create a client instance
  6. $client = new Client();
  7.  
  8. // Or auto create
  9. $client = Phalcon\Http\Client::factory();
  10.  
  11. // Send GET request
  12. $response = $client->get('http://localhost/');

POST 请求(POST Request)

  1. <?php
  2.  
  3. use Phalcon\Http\Client\Adapter\Curl as Client;
  4.  
  5. // Create a client instance
  6. $client = new Client();
  7.  
  8. // Send POST request
  9. $response = $client->post('http://localhost/auth/login', array('username' => 'test', 'password' => 'test'));

原文: http://www.myleftstudio.com/reference/http.html