ID: 49571 Updated by: srina...@php.net Reported By: info at pcxtra dot nl Status: To be documented Bug Type: Feature/Change Request Operating System: Windows XP PHP Version: 5.3.0 -Assigned To: +Assigned To: srinatar New Comment:
docs comments already provided. Previous Comments: ------------------------------------------------------------------------ [2009-09-24 18:28:30] srina...@php.net following needs to be documented Whenever there is a redirect request (either 301 or 302) , curl (against HTTP/1.1 spec) always follows with a GET request. However, if your applications wants compliance with HTTP/1.1 spec, and be able to issue a POST request after a POST redirect, user can use curl_setopt( <curl-handle>, CURLOPT_POSTREDIR, 3); here 3 tells curl module to redirect both 301 as well as 302 requests. 0,1,2,3 are the valid options for the last argument. 0 -> do not set any behavior 1 -> follow redirect with the same type of request only for 301 redirects. 2 -> follow redirect with the same type of request only for 302 redirects. 3 -> follow redirect with the same type of request both for 301 and 302 redirects. for example, if users wants the ability to redirect only for 301 requests, then they could use curl_setopt( <curl-handle>, CURLOPT_POSTREDIR, 1); ------------------------------------------------------------------------ [2009-09-24 18:20:50] s...@php.net Automatic comment from SVN on behalf of srinatar Revision: http://svn.php.net/viewvc/?view=revision&revision=288677 Log: - Fixed bug #49571 (CURLOPT_POSTREDIR not implemented). ------------------------------------------------------------------------ [2009-09-23 23:31:05] srina...@php.net hi hmm.. when i commented this below line in your example /* curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST"); */ i was able to get curl to send a 'GET' request after post returning a redirect. 127.0.0.1 - - [23/Sep/2009:16:25:51 -0700] "POST /curl.php?redir=true HTTP/1.1" 302 50 127.0.0.1 - - [23/Sep/2009:16:25:51 -0700] "GET /curl.php?start=true HTTP/1.1" 200 1323 127.0.0.1 - - [23/Sep/2009:16:25:51 -0700] "GET /curl.php?target=true HTTP/1.1" 200 4 similarly, when i changed the redirect to 302, i was also able to get curl to issue a 'get' request after a redirect. 127.0.0.1 - - [23/Sep/2009:16:25:13 -0700] "POST /curl.php?redir=true HTTP/1.1" 301 50 127.0.0.1 - - [23/Sep/2009:16:25:13 -0700] "GET /curl.php?target=true HTTP/1.1" 200 4 127.0.0.1 - - [23/Sep/2009:16:25:13 -0700] "GET /curl.php?start=true HTTP/1.1" 200 1333 now, here is a simple patch against 5.3, which allows you to do curl_setopt( $ch, CURLOPT_POSTREDIR, 3 ) and which forces curl to issue POST (or same request) after seeing a redirect. Index: ext/curl/interface.c =================================================================== --- ext/curl/interface.c (revision 288624) +++ ext/curl/interface.c (working copy) @@ -747,8 +747,10 @@ REGISTER_CURL_CONSTANT(CURLFTPSSL_CONTROL); REGISTER_CURL_CONSTANT(CURLFTPSSL_ALL); #endif + #if LIBCURL_VERSION_NUM > 0x071301 REGISTER_CURL_CONSTANT(CURLOPT_CERTINFO); + REGISTER_CURL_CONSTANT(CURLOPT_POSTREDIR); #endif /* SSH support works in 7.19.0+ using libssh2 */ @@ -1669,6 +1671,12 @@ } error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue)); break; +#if LIBCURL_VERSION_NUM > 0x071301 + case CURLOPT_POSTREDIR: + convert_to_long_ex(zvalue); + error = curl_easy_setopt(ch->cp, CURLOPT_POSTREDIR, Z_LVAL_PP(zvalue) & CURL_REDIR_POST_ALL); + break; +#endif case CURLOPT_PRIVATE: case CURLOPT_URL: case CURLOPT_PROXY: ------------------------------------------------------------------------ [2009-09-18 14:59:19] info at pcxtra dot nl I made a copy/paste failure... instead of: Now with CURLOPT_FOLLOWLOCATION=1 it goes wrong. I get [request_header] => POST /curl.php?redir=true HTTP/1.1 while I would expect the GET method. it should be: Now with CURLOPT_FOLLOWLOCATION=1 it goes wrong. I get [request_header] => POST /dev/impeng/curl.php?target=true HTTP/1.1 while I would expect the GET method. ------------------------------------------------------------------------ [2009-09-18 14:51:08] info at pcxtra dot nl I've completed a full running test. Please save it as curl.php and start it with curl.php?start=true. The idea is that it will do a POST to curl.php?redir=true. This page will response with 302 and redirect to curl.php?target=true. Now with CURLOPT_FOLLOWLOCATION=1 it goes wrong. I get [request_header] => POST /curl.php?redir=true HTTP/1.1 while I would expect the GET method. <?php $me = "http://". $_SERVER["SERVER_NAME"] . $_SERVER["SCRIPT_NAME"]; if( isset($_GET["redir"]) ) header("Location: ".$me."?target=true",TRUE,302); if( isset($_GET["target"]) ) { echo "done"; exit(); } if( isset($_GET["start"]) ) { $ch = curl_init( $me . "?redir=true"); curl_setopt( $ch, CURLINFO_HEADER_OUT, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 1 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, "data=somedata"); curl_setopt($ch, CURLOPT_MAXREDIRS, 1 ); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $content = curl_exec( $ch ); echo '<pre style="background-color:yellow">' . htmlspecialchars( print_r(curl_getinfo( $ch ), true) ). '</pre>'; echo '<pre style="background-color:#eeeeee">' . htmlspecialchars( $content ). '</pre>'; } echo "usage: ".$me."?start=true"; ?> ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/49571 -- Edit this bug report at http://bugs.php.net/?id=49571&edit=1