|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-16 13:54 UTC] info at pcxtra dot nl
Description: ------------ I'd like to use the CURLOPT_POSTREDIR. When I try to POST data to a page it will return with 302 and CURL will redirect with POST. However I need to configure this to redirect with GET which can be configured with CURLOPT_POSTREDIR which is added in curl 7.19.1. (I'm using PHP 5.3 with Curl 7.19.4) I also tried curl_setopt($ch, 161 , 0); (also tried 1,2 and 3) in the hope it would still work, but it didn't. Reproduce code: --------------- By POSTing something to an URL which returns 302 and the following settings: curl_setopt($ch, CURLOPT_MAXREDIRS, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); It will show with curl_getinfo: [request_header] => POST /Account/MyPortal.aspx HTTP/1.1 Expected result: ---------------- I would have expected (and wanted) [request_header] => GET /Account/MyPortal.aspx HTTP/1.1 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
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: