我正在尝试登录该网页以获取所需的统计信息。我使用的命令如下,
wget -v --no-check-certificate --no-cache --keep-session-cookies --save-headers --save-cookies / dev / stdout --post-data' username = unbt&安培;密码=" XXXX"' https://ip/login.cgi
从输出中,我得到了html文件并解析了它,我看到了,
<div id="errmsg" class="error"> ****Invalid credentials**.** </div>
相同的凭据通过浏览器正常工作。我传递凭证的方式有什么不对吗?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="shortcut icon" href="images/favicon.ico">
<link type="text/css" href="/150716.1130/css/style.css" rel="stylesheet"/>
<script type="text/javascript" src="/150716.1130/js/jquery.js"></script>
<script type="text/javascript" language="javascript">
//<!--
$(document).ready(function() {
$("#username").focus();
});
//-->
</script>
<style type="text/css">
#loginform {
text-align: center;
}
#loginform table {
margin: 0px auto;
text-align: left;
}
#loginform table tr {
}
table.loginsubtable {
margin: 80px auto;
}
table.loginsubtable td {
padding: 0 30px 0px 30px;
}
table.loginsubtable img {
border: 0px;
}
.loginsep {
border-left: 1px solid #dbdbdb;
}
.loginsep table td {
margin: 4px 2px 0px 2px;
white-space: nowrap;
padding: 5px 2px 0px 2px;
}
.loginsep label {
text-align: right;
color: white;
font-weight: normal;
white-space: nowrap;
}
.loginsep table td.submit {
text-align: right;
}
#submit {
text-align: center;
}
.error {
color: #f4324f;
font-weight: normal;
white-space: nowrap;
}
.license {
white-space: normal;
text-align: justify;
line-height: 1.8em;
width: 250px;
}
.error {
text-align: left;
white-space: normal;
}
</style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" align="center" class="loginsubtable">
<form enctype="multipart/form-data" id="loginform" method="post" action="/login.cgi">
<tr>
<td valign="top" style="padding-top: 38px"><img src="/150716.1130/images/tough-switch-pro-logo.png"></td>
<td class="loginsep" style="padding-right: 0">
<input type="hidden" name="uri" id="uri" value=" /" />
<table border="0" cellpadding="0" cellspacing="0" class="logintable" align="center">
<tr>
<td colspan="2" align="center">
<div id="errmsg" class="error">
</div>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><label for="username">Username:</label></td>
<td align="right"><input style="width: 145px" type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td align="right"><input style="width: 145px" type="password" name="password" id="password" maxlength="8"/></td>
</tr>
<tr>
<td colspan="2" valign="top" height="30" align="right"><input type="submit" value="Login" /></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
</body>
</html>
答案 0 :(得分:0)
编辑:在一个teamviewer调试会话之后,事实证明服务器有一个错误的Expect: 100-continue
实现,并且拒绝记录用户,这与用于表单数据的curl一样,但chrome没有,所以必须在curl中禁用标头(通过设置-H "Expect:"
)
似乎是您正在做的唯一错误,当服务器非常具体地说“使用multipart / form-data encoding”(<form enctype="multipart/form-data" id="loginform"
)时,尝试使用application / x-www-urlencoded编码请求进行登录 - 不幸的是,wget不支持multipart / form-data,但curl确实如此,所以可以使用curl吗?
curl -v --insecure -F username=unbt -F password=xxxx https://ip/login.cgi