POST form login credentials through redirect using wget

Viewed 94

I am trying to use bash and wget to POST form data to a login page and save the cookies after logging in. However, I have to go through an indirect URL that takes me to the login page through two redirects.

I've tried a variety of other methods using curl and wget to no avail. They all reach the page, but don't actually login.

All of the StackOverflow questions and articles I've read on the subject claim it's as easy as the wget call below.

wget \
  --save-cookies cookies.txt \
  --keep-session-cookies \
  --post-data "username=$username&password=$password" \
  "$indirect_url"

Here is an example wget output:

--2021-07-09 15:57:21--  https://<<indirect.url.1>>/
Resolving <<indirect.url.1>> (<<indirect.url.1>>)... <<indirect.ip.1>>
Connecting to <<indirect.url.1>> (<<indirect.url.1>>)|<<indirect.ip.1>>|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://<<indirect.url.2>> [following]

--2021-07-09 15:57:22--  https://<<indirect.url.2>>
Reusing existing connection to <<indirect.url.2>>:443.
HTTP request sent, awaiting response... 302 Found
Location: https://<<login.url.2>> [following]

--2021-07-09 15:57:22--  https://<<login.url>>
Resolving <<login.url>> (<<login.url>>)... <<login.ip>>
Connecting to <<login.url>> (<<login.url>>)|<<login.ip>>|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

index.html                    [ <=>                               ]   6.32K  --.-KB/s    in 0s      

2021-07-09 15:57:22 (284 MB/s) - ‘index.html’ saved [6473]

It seems to connect to the login page (200 response) and it downloads it, but it doesn't actually log me in, nor are the cookies.txt correct (e.g. no post-login cookies).

  1. Are the credentials not getting carried through the redirect?
  2. Is there something else I'm doing wrong?

Any help would be appreciated,

Thank you.

0 Answers
Related