使用curl测试JSP登录

使用curl测试JSP登录,jsp,curl,testing,login,Jsp,Curl,Testing,Login,我试图使用curl验证网页的凭据(用户/密码),但我尝试了很多方法 我得到了Chrome开发者工具的一些支持,可以使用网络或控制台工具生成所需的字符串 URL:http://localhost:8080/site/login.do 建议使用Chrome工具: curl 'http://localhost:8080/egsdp/j_security_check' \ -H 'Connection: keep-alive' \ -H 'Cache-Control: max-age=0

我试图使用curl验证网页的凭据(用户/密码),但我尝试了很多方法

我得到了Chrome开发者工具的一些支持,可以使用网络或控制台工具生成所需的字符串

URL:
http://localhost:8080/site/login.do

建议使用Chrome工具:

curl 'http://localhost:8080/egsdp/j_security_check' \
    -H 'Connection: keep-alive' \
    -H 'Cache-Control: max-age=0' \
    -H 'Origin: http://localhost:8080' \
    -H 'Upgrade-Insecure-Requests: 1' \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36' \
    -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' \
    -H 'Referer: http://localhost:8080/egsdp/login.do' \
    -H 'Accept-Encoding: gzip, deflate, br' \
    -H 'Accept-Language: es-ES,es;q=0.9,de;q=0.8,en;q=0.7,fr;q=0.6,it;q=0.5,pt;q=0.4,sr;q=0.3,tr;q=0.2,zh-CN;q=0.1,zh;q=0.1,gl;q=0.1' \
    -H 'Cookie: JSESSIONID=100E2B441254401942BF64876B18F584' \
    --data 'j_username=root&j_password=AWYc2d9%2B1mc%3D' \
    --compressed
我查看了登录网页的源代码:

<div id="formulario">
  <form method="post" id="formLogin" action="">
    <table align="center" border="0" cellspacing="5">
      <tr>
        <th align="right">Usuario:</th>
        <td align="left">
          <input type="text" name="j_username" size="15"> 
        </td>
      </tr>
      <tr>
        <th align="right">Contrase?a :</th>
        <td align="left">
          <input type="password" name="j_password" id="j_password" size="15">
        </td>
      </tr>
    </table>
  </form>
</div>

<table align="center" border="0" cellspacing="5">
  <tr>
    <td align="right"><input type="button" value="Login"
        onclick="javascript:peticion()">
    </td>
  </tr>
  </table>
</div>

乌萨里奥:
相反?a:

我的卷曲有什么问题?

我想您需要在卷曲参数中添加
-X POST
。表单应该是通过POST发送的,但是curl默认情况下会发送GET。您还可以在curl中为详细模式添加
-v
。此外,如果您引用
j_security\u check
servlet本身,您很可能会遇到类似于登录页面本身的异常
j_security_check
保护的是您试图访问的资源,而不是登录页面。