3 ## Sending a simple GET request:
7 $request = new http\Client\Request("GET",
9 ["User-Agent"=>"My Client/0.1"]
11 $request->setOptions(["timeout"=>1]);
13 $client = new http\Client;
14 $client->enqueue($request)->send();
16 // pop the last retrieved response
17 $response = $client->getResponse();
18 printf("%s returned '%s' (%d)\n",
19 $response->getTransferInfo("effective_url"),
21 $response->getResponseCode()
27 http://localhost/ returned 'HTTP/1.1 200 OK' (200)
30 ## Submitting a standard form:
34 $request = new http\Client\Request("POST",
35 "http://localhost/post.php",
36 ["Content-Type" => "application/x-www-form-urlencoded"]
38 $request->getBody()->append(new http\QueryString([
40 "name" => "Michael Wallner"
43 $client = new http\Client;
44 $client->setOptions(["ssl" => [
45 "version" => http\Client\Curl\SSL_VERSION_TLSv1
47 $client->enqueue($request)->send();
49 // ask for the response for this specific request
50 $response = $client->getResponse($request);
51 printf("-> %s\n", $response->getInfo());
60 ## Submitting a multipart form:
64 $request = new http\Client\Request("POST",
65 "http://localhost/post.php"
68 // http\Message\Body::addForm() will automatically add
69 // Content-Type: multipart/form-data to the request headers
70 $request->getBody()->addForm([
72 "name" => "Michael Wallner"
76 "type" => "image/jpeg",
81 $client = new http\Client;
82 $client->setOptions(["ssl" => [
83 "version" => http\Client\Curl\SSL_VERSION_TLSv1
85 $client->enqueue($request)->send();
87 // ask for the response for this specific request
88 $response = $client->getResponse($request);
89 printf("-> %.2F kB\n @ %.2F Mbit",
90 .001 * $response->getTransferInfo("size_upload"),
91 .0000008 * $response->getTransferInfo("speed_upload")
97 -> 15.98 kB @ 6.77 Mbit