asp.net对象移动了

时间:2011-07-22 09:44:18

标签: java asp.net http-post

String parameters = "__VIEWSTATE=" + "__EVENTTARGET="
                + "__EVENTARGUMENT=" + "&ctl00$tbUsername="
                + URLEncoder.encode("name", "UTF-8") + "&ctl00$tbPwd="
                + URLEncoder.encode("pssw", "UTF-8")
                + "&ctl00$chkRememberLogin=" + URLEncoder.encode("0", "UTF-8")
                + "&ctl00$cmdLogin=" + URLEncoder.encode("Login", "UTF-8");
    URL url;
    HttpURLConnection connection = null;
    try {
        url = new URL("www.website.com/Login.aspx");
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type",
                "text/html; charset=utf-8");
        connection.setRequestProperty("Content-Length",
                "" + Integer.toString(parameters.getBytes().length));
//trying everything..
        connection.setDefaultUseCaches(true);
        connection.setUseCaches(true);

        connection.setUseCaches(true);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setAllowUserInteraction(true);
        connection.setInstanceFollowRedirects(true);
        HttpURLConnection.setFollowRedirects(true);

        DataOutputStream wr = new DataOutputStream(
                connection.getOutputStream());
        wr.writeBytes(parameters);
        wr.flush();
        wr.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            connection.disconnect();
        }

    }
}

这是一个HTML表单

<form id="LoginForm" name="LoginForm" method="post" action="Login.aspx?__ufps=747201&loggedout">
<input type="hidden" name="__VIEWSTATE" value="/wEXAQUDX19QD2QPBirKUk9SFs6IZg==">
<input type="hidden" name="__EVENTTARGET" value="">
<input type="hidden" name="__EVENTARGUMENT" value="">
<script language=javascript><!--
function __doPostBack(target, argument){
  var theform = document.LoginForm
  theform.__EVENTTARGET.value = target
  theform.__EVENTARGUMENT.value = argument
  theform.submit()
}
// -->
</script>

<div nowrap><b>Username:</b></div><input name="ctl00$tbUsername" /><br>
<b>Password:</b><br>
<input name="ctl00$tbPwd" type="password"/><br>
<input type="checkbox" name="ctl00$chkRememberLogin" value="0" checked>Remember Me<br>
<input name="ctl00$cmdLogin" type="submit" value="Login"/>&nbsp;
                        <input name="ctl00$cmdForgetMe" type="submit" value="Forget Me"/>
</form>

回复消息是:“对象移动到此处”。 #%^#%^?有人可以解释可能出错的地方...... WireShark显示来自客户端和浏览器的相同帖子请求

P.S。知道的人,请帮忙..

1 个答案:

答案 0 :(得分:0)

根据我的理解,您尝试通过邮件发送名称和密码,然后您会收到重定向消息!从网页上说你要读到不同的位置。

这是因为

  1. 您尝试使用不安全的页面,服务器会将您重定向到安全的SSL。
  2. 发布后,服务器会将数据和响应重定向到新页面。