无法使用wget登录网站

unable login to website using wget

我正在尝试使用 wget 登录网站。表格看起来像这样。

<form name='frmLogin' action='Login' method='post'>
  <table class='login'>
    <tr>
      <td class='label'>
        <div class='alignRight'>Username: <span class='mandatory'>*</span></div>
      </td>
      <td class='field'>
        <input type='text' name='txtUsername' size='10' maxlength='10' value='' onBlur="validatePassword(this, true)" onKeyPress="checkText(this, event)">
      </td>
    </tr>
    <tr>
      <td class='label'>
        <div class='alignRight'>Password: <span class='mandatory'>*</span></div>
      </td>
      <td class='field'>
        <input type='password' name='txtPassword' size='10' maxlength='10' value='' onBlur="validatePassword(this, true)" onKeyPress="checkText(this, event)">
      </td>
    </tr>
  </table>
  <div class='toolbar'>
    <input type='button' class='button' name='btnSubmit' value='Login' onClick="javascript:formSubmit()" />
    <input type='reset' class='button' name='btnReset' value='Clear' />
    <input type='button' class='button' name='btnExit' value='Exit' onClick="javascript:navigateTo('index.jsp')" />
  </div>
</form>

我正在使用以下命令登录并保存 cookie 并使用该 cookie 访问页面。但是当我使用那个 cookie 时,会话已过期。

进行登录

wget  --no-check-certificate --auth-no-challenge --keep-session-cookies --save-cookies cookie104.txt --header="Cookie: $cookie" --post-data="txtUsername=$name&txtPassword=$pass&btnSubmit=Login" ${site}login.jsp

加载主页

wget --load-cookie cookie104.txt --no-check-certificate ${site}home.jsp

Cookie 内容:

cat cookie104.txt 
# HTTP cookie file.
# Generated by Wget on 2017-01-19 13:54:37.
# Edit at your own risk.

xyz02.com   FALSE   /dpl    FALSE   0   JSESSIONID  AA86E0BCE03A3D419953A928E590F184

主页的输出:

HTTP request sent, awaiting response... 302 Found
Location: login.jsp?msg=Your current session has expired. Please log in again. [following]
--2017-01-19 13:54:38--  https://xyz02.com/dpl/login.jsp?msg=Your%20current%20session%20has%20expired.%20Please%20log%20in%20again.

请告知我在这里遗漏了什么。我的目的是从主页获取详细信息并使用 sendmail 将它们发送到电子邮件中。

302 表示您正在被重定向,wget 停在那里,因为这是 HTTP 事务的结束。

您应该使用 curl 到 "follow" 重定向,如 this answer