Is there a way to follow redirects with command line cURL?
I know that in a php script:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
will follow redirects. Is there a way to follow redirects with command line cURL?
使用位置标题标志:
curl -L <URL>
I had a similar problem. I am posting my solution here because I believe it might help one of the commenters.
For me, the obstacle was that the page required a login and then gave me a new URL through javascript. Here is what I had to do:
curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword" <URL>
Note that j_username and j_password is the name of the fields for my website's login form. You will have to open the source of the webpage to see what the 'name' of the username field and the 'name' of the password field is in your case. After that I go an html file with java script in which the new URL was embedded. After parsing this out just resubmit with the new URL:
curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword" <NEWURL>
上一篇: 如何通过GDI的DrawImage(非标定)提高性能?
下一篇: 有没有办法使用命令行cURL跟踪重定向?