1 # class http\Client implements SplSubject, Countable
3 The HTTP client. See http\Client\Curl's [options](http/Client/Curl#Options:) which is the only driver currently supported.
9 2.3.0 | Deprecated methods:<br>http\Client::enablePipelining() and <br>http\Client::enableEvents().<br>Added Methods:<br>http\Client::configure(),<br>http\Client::getAvailableConfiguration() and<br>http\Client::getAvailableOptions().
13 ### Sending a simple GET request:
17 $request = new http\Client\Request("GET",
19 ["User-Agent"=>"My Client/0.1"]
21 $request->setOptions(["timeout"=>1]);
23 $client = new http\Client;
24 $client->enqueue($request)->send();
26 // pop the last retrieved response
27 $response = $client->getResponse();
28 printf("%s returned '%s' (%d)\n",
29 $response->getTransferInfo("effective_url"),
31 $response->getResponseCode()
37 http://localhost/ returned 'HTTP/1.1 200 OK' (200)
40 ### Submitting a standard form:
44 $request = new http\Client\Request("POST",
45 "http://localhost/post.php",
46 ["Content-Type" => "application/x-www-form-urlencoded"]
48 $request->getBody()->append(new http\QueryString([
50 "name" => "Michael Wallner"
53 $client = new http\Client;
54 $client->setOptions(["ssl" => [
55 "version" => http\Client\Curl\SSL_VERSION_TLSv1
57 $client->enqueue($request)->send();
59 // ask for the response for this specific request
60 $response = $client->getResponse($request);
61 printf("-> %s\n", $response->getInfo());
70 ### Submitting a multipart form:
74 $request = new http\Client\Request("POST",
75 "http://localhost/post.php"
78 // http\Message\Body::addForm() will automatically add
79 // Content-Type: multipart/form-data to the request headers
80 $request->getBody()->addForm([
82 "name" => "Michael Wallner"
86 "type" => "image/jpeg",
91 $client = new http\Client;
92 $client->setOptions(["ssl" => [
93 "version" => http\Client\Curl\SSL_VERSION_TLSv1
95 $client->enqueue($request)->send();
97 // ask for the response for this specific request
98 $response = $client->getResponse($request);
99 printf("-> %.2F kB\n @ %.2F Mbit",
100 .001 * $response->getTransferInfo("size_upload"),
101 .0000008 * $response->getTransferInfo("speed_upload")
107 -> 15.98 kB @ 6.77 Mbit
112 * private SplObjectStorage $observers = NULL
114 * protected array $options = NULL
116 * protected http\Message $history = NULL
117 Request/response history.
118 * public bool $recordHistory = false
119 Whether to record history in http\Client::$history.