2

Web ページにログインしてファイルをダウンロードするためのカスタム プログラム (またはスクリプト) を作成しようとしています。ログイン ページには、2 つのテキスト フィールド (ユーザー名とパスワード) と隠しフィールド "authenticity_token" を含むフォームがあります。認証トークンについて読みました。

curl を使用してカスタム bash スクリプトを試しましたが、うまくいきません。誰でも私のコードを見て、何が問題なのか教えてもらえますか?

#!/bin/bash
#Pulls the login page and strips out the auth token
authToken=`curl -L -c cookies.txt --silent 'http://xxx.xxxxx.xx' | grep authenticity_token | awk -F'value="' '{print $2;}' | awk -F'="' '{print $1;}'`

echo $authToken

# Posts all the pre-URI-encoded stuff and appends the URI-encoded auth token
curl -L -c cookies.txt -b cookies.txt --data-urlencode authenticity_token=$authToken  --data-urlencode 'username=my-username' --data-urlencode 'password=my-pass'  'http://xxx.xxxxx.xxx/login' 

# access the page i want
curl -b cookies 'http://xxx.xxxxx.xxx/page_i_want_to_access'

ブラウザを使用してWebページにログインすると、ログが成功するとサーバーは次のページにリダイレクトしますが、スクリプトを使用すると、サーバーはヘッダーが「302リダイレクト」ではなく「200 OK」であるパケットで応答します(私はパケットをキャプチャするためにwiresharkを使用しています)。したがって、認証が機能していないと思います。

何か提案はありますか?

4

0 に答える 0