From 9daae806d5a3883373e17acd9d80bebcffa6dff0 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 17 Jul 2016 15:09:50 -0700 Subject: [PATCH] Move post/redirect/get example to examples --- README.md | 20 -------------------- examples/post_redirect_get.php | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 examples/post_redirect_get.php diff --git a/README.md b/README.md index 85b8399..c3a1c8e 100644 --- a/README.md +++ b/README.md @@ -53,28 +53,8 @@ $curl->post('http://www.example.com/login/', array( 'username' => 'myusername', 'password' => 'mypassword', )); - -// Perform a post-redirect-get request (POST data and follow 303 redirections using GET requests). -$curl = new Curl(); -$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬ -$curl->post('http://www.example.com/login/', array( - 'username' => 'myusername', - 'password' => 'mypassword', -)); - -// POST data and follow 303 redirections by POSTing data again. -// Please note that 303 redirections should not be handled this way: -// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 -$curl = new Curl(); -$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);¬ -$curl->post('http://www.example.com/login/', array( - 'username' => 'myusername', - 'password' => 'mypassword', -), false); ``` -A POST request performs by default a post-redirect-get (see above). Other request methods force an option which conflicts with the post-redirect-get behavior. Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not possible to reset this option. It is therefore impossible to perform a post-redirect-get request using a php-curl-class Curl object that has already been used to perform other types of requests. Either use a new php-curl-class Curl object or upgrade your PHP engine. - ```php $curl = new Curl(); $curl->setBasicAuthentication('username', 'password'); diff --git a/examples/post_redirect_get.php b/examples/post_redirect_get.php new file mode 100644 index 0000000..5b8d885 --- /dev/null +++ b/examples/post_redirect_get.php @@ -0,0 +1,27 @@ +setOpt(CURLOPT_FOLLOWLOCATION, true); +$curl->post('http://www.example.com/login/', array( + 'username' => 'myusername', + 'password' => 'mypassword', +)); + +// POST data and follow 303 redirections by POSTing data again. Please note +// that 303 redirections should not be handled this way. +// https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 +$curl = new Curl(); +$curl->setOpt(CURLOPT_FOLLOWLOCATION, true); +$curl->post('http://www.example.com/login/', array( + 'username' => 'myusername', + 'password' => 'mypassword', +), false); + +// A POST request performs a post-redirect-get by default. Other request +// methods force an option which conflicts with the post-redirect-get behavior. +// Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not +// possible to reset this option. It is therefore impossible to perform a +// post-redirect-get request using a php-curl-class Curl object that has already +// been used to perform other types of requests. Either use a new php-curl-class +// Curl object or upgrade your PHP engine.