在远程Linux服务器上,通过firefox命令,通过X协议,在本地节点显示浏览器,提交表单,操作十分缓慢。但是有时候只是操作一些简单的post操作。

这时候,可以使用curl命令,进行默认提交,可以产生相同的效果。

示例:

公司必须外网访问之前需要认证。在打开外部网页时,会自动跳转到认证页面,提示认证。但是远程服务器通过firefox打开页面实在是慢,敲入一个字母后,要等到10分钟该字母才能回显。有时候敲多了敲快了,10分钟回显出来后,修正地址又有10分钟,实在是不能忍。

解决办法:

  1. 输入:wget www.baidu.com ,获取认证页面内容。
  2. 查看页面:查看页面内容:
root@node1:~# cat index.html
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html  ns=\"http://www.w3.org/1999/xhtml\">
<head>
<  http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />
< >身份认证系统</ >
<style type=\"text/css\">
body { margin: 0px; font-size: 12px; background: #F8F8F8; }
.logindiv_bj { height: 265px; width: 800px;; top: 50%; left: 50%; position:absolute; z-index:100; margin-top: -150px; margin-left: -400px; 
}.logindiv { height: 265px; width: 500px; margin: 0px auto; }
.logindiv ul { margin: 0px; padding: 0px; list-style: url(none) none; }
.logindiv ul li { border-top: 1px solid #333; border-right: 1px solid #333; border-left: 1px solid #333; margin: 0px; padding: 0px; }
</style>
<  src=\"./ s/index.js\"></ >
</head>
<body style=\"overflow:scroll;overflow:hidden;\"  =\"init()\">
<form id=\"form1\" method=post>
  <div class=\"logindiv_bj\">
    <div class=\"logindiv\">
      <ul>
        <li style=\"background-color:#F0F0F0;\"><img src=\"images/ .jpg\" /></li>
        <li style=\" padding:30px;\">
          <table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\">
            <tr>
              <td width=\"94\" align=\"right\">用户名: </td>
              <td width=\"386\" align=\"left\">
                <input name=\"username\" id=\"username\" type=\"text\" size=\"20\" style=\"width:200px \">
              </td>
            </tr>
            <tr>
              <td align=\"right\" nowrap=\"nowrap\" class=\"formtxt\">密  码: </td>
              <td align=\"left\" nowrap=\"nowrap\" class=\"formtxt\">
                <input id=\"passwd\" name=\"passwd\" type=\"password\" size=\"22\" style=\"width:200px \">
                <input id=\"pwd\" type=\"hidden\" name=\"pwd\" value=\"\">
              </td>
            </tr>
            <tr>
              <td colspan=\"2\" align=\"center\">
                <div style=\"padding:10px 150px 10px 10px;\">
                  <input style=\"CURSOR: hand; height:26px; width:50px;\" type=\"submit\"  =\" :return onApply();\" value=\"登 录\" 
>                  <input style=\"CURSOR: hand;height:26px; width:50px;\"  type=\"reset\"  value=\"清 空\">
                </div>
              </td>
            </tr>
          </table>
        </li>
        <li style=\"border-bottom:1px solid #333; padding:10px;\" ><span style=\"color:#F30; \">提示信息:</span><span id=\"err_info\" style=\" co
lor:#666\">在您使用网络之前,需要进行验证。</span></li>      </ul>
    </div>
  </div>
  </div>
</form>
</body>
</html>

  1. 观察页面,发现页面主要是一个表单<form id=\"form1\" method=post> 。另外,该表单有两个参数:

用户名:

 <input name=\"username\" id=\"username\" type=\"text\" size=\"20\" style=\"width:200px \">

用户密码:

 <input id=\"pwd\" type=\"hidden\" name=\"pwd\" value=\"\">

两个按钮:

 <input style=\"CURSOR: hand; height:26px; width:50px;\" type=\"submit\"  =\" :return onApply();\" valu>                
  <input style=\"CURSOR: hand;height:26px; width:50px;\"  type=\"reset\"  value=\"清 空\">

认证过程就是给登录URL发送用户名,密码的过程。

  1. 使用curl默认该过程,发送
 curl  -d \"username=test&pwd=123456\"  http://serverIP/webAuth/index.htm/form1

其中,curl发送参数名字usernamepwd 是页面定义的两个参数名字,form1 是页面定义的表单的名字。

  1. 测试。认证完成后,重新执行:wget www.baidu.com
  2. 查看页面:cat index.html 。认证成功,显示百度首页了
root@node1:~# cat index.html
<!DOCTYPE html>
<!--STATUS OK--><html> <head><  http-equiv=content-type content=text/html;charset=utf-8><  http-equiv=X-UA-Compatible conte
><  content=always name=referrer><  rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.cs百度一下,你就知道</ ></head> <body  =#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> =s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form ion=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=h=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=bailass=\"bg s_ipt_wr\"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class=\"bg s_btn_wtype=submit id=su value=百度一下 class=\"bg s_btn\"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tjass=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmapv>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mn> <no > <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 nin class=lb>登录</a> </no > < >document.write(\'<a href=\"http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=\'+ encodeUR(window.location.href+ (window.location.search === \"\" ? \"?\" : \"&\")+ \"bdorz_come=1\")+ \'\" name=\"tj_login\" class=\"lb\">登录</a>\');</shref=//www.baidu.com/more/ name=tj_briicon class=bri style=\"display: block;\">更多产品</a> </div> </div> </div> <div id=ftCon> <diw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbspp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbs30173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
收藏 打印