Data attached to POST request is gone during redirection to GET with CURL
From curl's manpage:
When curl follows a redirect and the request is not a plain GET (for example POST or PUT), it will do the following request with a GET if the HTTP response was 301, 302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.
Edit
I did some research and found out, that it might be a problem with your curl version. Newer version will honour the -XPOST
option and will POST
to the redirected location as well. But older versions had an own option for this, i.e. --post301
and --post302
. According to their manpage:
--post301Tells curl to respect RFC 2616/10.3.2 and not convert POST requests into GETrequests when following a 301 redirection. The non-RFC behaviour is ubiquitousin web browsers, so curl does the conversion by default to maintainconsistency. However, a server may require a POST to remain a POST after sucha redirection. This option is meaningful only when using -L, --location(Added in 7.17.1)
--post302Tells curl to respect RFC 2616/10.3.2 and not convert POST requests into GETrequests when following a 302 redirection. The non-RFC behaviour is ubiquitousin web browsers, so curl does the conversion by default to maintainconsistency. However, a server may require a POST to remain a POST after sucha redirection. This option is meaningful only when using -L, --location(Added in 7.19.1)
References:
I need to add -b
to my script to enable the cookies. CURL by default doesn't use them and this issue caused to session ID change. Therefore no data transferred.
curl -b -L -i -X POST \ -d 'id=105' \ -d 'json={"orderBy":0,"maxResults":50}' http://mysite.com/ctlClient/
Now its working