X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http%2FClient.md;h=64d7aa8f1fc1e0c7a2db170553875a136b4233e4;hb=b3ce1560d9964179e2f6ec29d4acf655b490e889;hp=eb36e737a8c9842bb7d1d936590462777cd1a6c9;hpb=d93aa147045cc3bd7a6c8af933e44dcae3888add;p=mdref%2Fmdref-http diff --git a/http/Client.md b/http/Client.md index eb36e73..64d7aa8 100644 --- a/http/Client.md +++ b/http/Client.md @@ -1,6 +1,105 @@ -# class http\Client implements SplSubject +# class http\Client implements SplSubject, Countable + +The HTTP client. The only driver currently supported is http\Client\Curl. + +## Examples: + +### Sending a simple GET request: + + "My Client/0.1"] + ); + $request->setOptions(["timeout"=>1]); + + $client = new http\Client; + $client->enqueue($request)->send(); + + // pop the last retrieved response + $response = $client->getResponse(); + printf("%s returned '%s' (%d)\n", + $response->getTransferInfo("effective_url"), + $response->getInfo(), + $response->getResponseCode() + ); + ?> + +#### Yields: + + http://localhost/ returned 'HTTP/1.1 200 OK' (200) + + +### Submitting a standard form: + + "application/x-www-form-urlencoded"] + ); + $request->getBody()->append(new http\QueryString([ + "user" => "mike", + "name" => "Michael Wallner" + ])); + + $client = new http\Client; + $client->setOptions(["ssl" => [ + "version" => http\Client\Curl\SSL_VERSION_TLSv1 + ]]); + $client->enqueue($request)->send(); + + // ask for the response for this specific request + $response = $client->getResponse($request); + printf("-> %s\n", $response->getInfo()); + + ?> + +#### Yields: + + -> HTTP/1.1 200 OK + + +### Submitting a multipart form: + + getBody()->addForm([ + "user" => "mike", + "name" => "Michael Wallner" + ], [ + [ + "name" => "image", + "type" => "image/jpeg", + "file" => "image.jpg" + ] + ]); + + $client = new http\Client; + $client->setOptions(["ssl" => [ + "version" => http\Client\Curl\SSL_VERSION_TLSv1 + ]]); + $client->enqueue($request)->send(); + + // ask for the response for this specific request + $response = $client->getResponse($request); + printf("-> %.2F kB\n @ %.2F Mbit", + .001 * $response->getTransferInfo("size_upload"), + .0000008 * $response->getTransferInfo("speed_upload") + ); + ?> + +#### Yields: + + -> 15.98 kB @ 6.77 Mbit -The HTTP client. ## Properties: