diff --git a/examples/delete.php b/examples/delete.php new file mode 100644 index 0000000..502578e --- /dev/null +++ b/examples/delete.php @@ -0,0 +1,25 @@ +delete('https://httpbin.org/delete', + array( + 'key' => 'value', + ), + array( + 'a' => '1', + 'b' => '2', + 'c' => '3', + ) +); + +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Data server received via DELETE:' . "\n"; + var_dump($curl->response->form); +} diff --git a/examples/get.php b/examples/get.php index f1017b3..a647fbd 100644 --- a/examples/get.php +++ b/examples/get.php @@ -3,8 +3,12 @@ require __DIR__ . '/vendor/autoload.php'; use \Curl\Curl; +// curl --request GET "https://httpbin.org/get?key=value" + $curl = new Curl(); -$curl->get('https://httpbin.org/get'); +$curl->get('https://httpbin.org/get', array( + 'key' => 'value', +)); if ($curl->error) { echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; diff --git a/examples/head.php b/examples/head.php new file mode 100644 index 0000000..f48f370 --- /dev/null +++ b/examples/head.php @@ -0,0 +1,18 @@ +head('http://127.0.0.1:8000/', array( + 'key' => 'value', +)); + +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Response headers:' . "\n"; + var_dump($curl->responseHeaders); +} diff --git a/examples/options.php b/examples/options.php new file mode 100644 index 0000000..f055d92 --- /dev/null +++ b/examples/options.php @@ -0,0 +1,18 @@ +options('http://127.0.0.1:8000/', array( + 'foo' => 'bar', +)); + +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Response:' . "\n"; + var_dump($curl->response); +} diff --git a/examples/patch.php b/examples/patch.php new file mode 100644 index 0000000..9e74920 --- /dev/null +++ b/examples/patch.php @@ -0,0 +1,20 @@ +patch('https://httpbin.org/patch', array( + 'a' => '1', + 'b' => '2', + 'c' => '3', +)); + +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Response:' . "\n"; + var_dump($curl->response); +} diff --git a/examples/post.php b/examples/post.php index 9ea4adc..5f6a63a 100644 --- a/examples/post.php +++ b/examples/post.php @@ -3,17 +3,18 @@ require __DIR__ . '/vendor/autoload.php'; use \Curl\Curl; -// curl \ -// -X POST \ -// -d "id=1&content=Hello+world%21&date=2015-06-30+19%3A42%3A21" \ -// "https://httpbin.org/post" +// curl --request POST "https://httpbin.org/post" --data "id=1&content=Hello+world%21&date=2015-06-30+19%3A42%3A21" -$data = array( +$curl = new Curl(); +$curl->post('https://httpbin.org/post', array( 'id' => '1', 'content' => 'Hello world!', 'date' => date('Y-m-d H:i:s'), -); +)); -$curl = new Curl(); -$curl->post('https://httpbin.org/post', $data); -var_dump($curl->response->form); +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Data server received via POST:' . "\n"; + var_dump($curl->response->form); +} diff --git a/examples/put.php b/examples/put.php index 338873b..b14d7d1 100644 --- a/examples/put.php +++ b/examples/put.php @@ -3,13 +3,18 @@ require __DIR__ . '/vendor/autoload.php'; use \Curl\Curl; -// curl -X PUT -d "id=1&first_name=Zach&last_name=Borboa" "https://httpbin.org/put" +// curl --request PUT "https://httpbin.org/put" --data "id=1&first_name=Zach&last_name=Borboa" + $curl = new Curl(); $curl->put('https://httpbin.org/put', array( - 'id' => 1, + 'id' => '1', 'first_name' => 'Zach', 'last_name' => 'Borboa', )); -echo 'Data server received via PUT:' . "\n"; -var_dump($curl->response->form); +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Data server received via PUT:' . "\n"; + var_dump($curl->response->form); +} diff --git a/examples/search.php b/examples/search.php new file mode 100644 index 0000000..bfc030d --- /dev/null +++ b/examples/search.php @@ -0,0 +1,20 @@ +search('http://127.0.0.1:8000/', array( + 'a' => '1', + 'b' => '2', + 'c' => '3', +)); + +if ($curl->error) { + echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; +} else { + echo 'Response:' . "\n"; + var_dump($curl->response); +}