Curl can't follow "This page should automatically redirect"

0

I'm attempting to automate a login for the a course webpage I have to check this semester. I know that the POST request I am making is being done correctly because I get to the intermediate redirect page that you only get on a successful login.

I'm basically hitting one of those This page should automatically redirect. If nothing is happening please use the continue link below. pages. Unfortunately because curl isn't following this final redirect, it doesn't seem to be setting the last cookies to keep my session.

I've been reading the man for curl, but I can't seem to find the correct way to get this done (--max-time and --max-redirs are what I've tried and aren't working).

Can anyone tell me what I need to do to resolve this?

Here's what' I'm working with

LOGINURL="http://www.[redacted].edu/login/index.php" # This is not https because they don't support it.
COURSEURL="http://www.[redacted].edu/course/[redacted]"
USERAGENT="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0"
COOKIEJAR="${HOME}/edu.cookies"
POSTDATA="[redacted]"
curl -o "index.html" --referer "${LOGINURL}" --user-agent "${USERAGENT}" --cookie-jar "${COOKIEJAR}" --data "${POSTDATA}" "${LOGINURL}"
curl -o "course.html" --referer "${LOGINURL}" --user-agent "${USERAGENT}" --cookie "${COOKIEJAR}" "${COURSEURL}"

PS, the link that is provided on the intermediate redirect page is the same link as the COURSEURL url, so manually curling it does not work.

Paul Nelson Baker

Posted 2014-08-29T21:56:48.600

Reputation: 155

Do you know what kind of redirect they're using? Javascript? Server side? META refresh? – ernie – 2014-08-29T22:17:25.967

1@ernie I just barely saw your comment, it's a server-side redirect. The page's source doesn't have any Javascript or have a Meta-Refresh. It turns out all curl needed was -L. – Paul Nelson Baker – 2014-08-29T22:23:45.830

Answers

0

I feel absolutely silly. The -L option was all I needed. From the man page:

-L, --location
              (HTTP/HTTPS)  If  the  server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code),
              this option will make curl redo the request on the new place. If used together with -i, --include or -I, --head, headers from all requested  pages  will  be
              shown.  When  authentication is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won't be able to
              intercept the user+password. See also --location-trusted on how to change this. You can limit the amount of redirects to follow by  using  the  --max-redirs
              option.

              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.

Paul Nelson Baker

Posted 2014-08-29T21:56:48.600

Reputation: 155