1 # class http\Client implements SplSubject, Countable
3 The HTTP client. The only driver currently supported is http\Client\Curl.
7 ### Sending a simple GET request:
11 $request = new http\Client\Request("GET",
13 ["User-Agent"=>"My Client/0.1"]
15 $request->setOptions(["timeout"=>1]);
17 $client = new http\Client;
18 $client->enqueue($request)->send();
20 // pop the last retrieved response
21 $response = $client->getResponse();
22 printf("%s returned '%s' (%d)\n",
23 $response->getTransferInfo("effective_url"),
25 $response->getResponseCode()
31 http://localhost/ returned 'HTTP/1.1 200 OK' (200)
34 ### Submitting a standard form:
38 $request = new http\Client\Request("POST",
39 "http://localhost/post.php",
40 ["Content-Type" => "application/x-www-form-urlencoded"]
42 $request->getBody()->append(new http\QueryString([
44 "name" => "Michael Wallner"
47 $client = new http\Client;
48 $client->setOptions(["ssl" => [
49 "version" => http\Client\Curl\SSL_VERSION_TLSv1
51 $client->enqueue($request)->send();
53 // ask for the response for this specific request
54 $response = $client->getResponse($request);
55 printf("-> %s\n", $response->getInfo());
64 ### Submitting a multipart form:
68 $request = new http\Client\Request("POST",
69 "http://localhost/post.php"
72 // http\Message\Body::addForm() will automatically add
73 // Content-Type: multipart/form-data to the request headers
74 $request->getBody()->addForm([
76 "name" => "Michael Wallner"
80 "type" => "image/jpeg",
85 $client = new http\Client;
86 $client->setOptions(["ssl" => [
87 "version" => http\Client\Curl\SSL_VERSION_TLSv1
89 $client->enqueue($request)->send();
91 // ask for the response for this specific request
92 $response = $client->getResponse($request);
93 printf("-> %.2F kB\n @ %.2F Mbit",
94 .001 * $response->getTransferInfo("size_upload"),
95 .0000008 * $response->getTransferInfo("speed_upload")
101 -> 15.98 kB @ 6.77 Mbit
106 * private $observers = NULL
107 SplObjectStorage, attached observers.
108 * protected $options = NULL
109 Array of set options.
110 * protected $history = NULL
111 http\Message request/response history.
112 * public $recordHistory = false
113 Boolean flag whether to record history in http\Client::$history.