利用java的post模拟登录网站时,hiden参数问题
我现在是要用java post编写一个模拟网页登陆的程序,在用post提交参数时,除了用户名和密码外,还必须提供两个hiden的参数,否则无法登录,请问如何获取这两个影藏的参数,也就是说服务器会不会传回一些参数里面含有这种hiden的值,一般传回的值会放在那里,我用java的什么函数去获取?谢谢了!!! --------------------编程问答-------------------- hiddle和text的类型差不多,都可以用request.getParameter("textName")获得,唯一不同的地方是hiddle是隐藏的,在客户端的浏览器看不到。这些值都是传递给服务器的,当然也可以写在jsp页面里面,由另外一个jsp页面获得。。。但是 说到底,还是由服务器获得的。。。 --------------------编程问答--------------------
差不多、不过你问服务器是否传回这些参数。。这个是看你要不要这些参数。要的话就有可以用在客服端获得request.getParameter("参数Name"); --------------------编程问答-------------------- 对不起,我实在是个菜鸟,对这个真不懂,请问request在java se 里面是如何定义的 --------------------编程问答-------------------- 还有就是我是想在客户端获得这个隐藏的值,你刚才给的request.getParameter("textName")方法应该是再服务器端获取客户端传入的值吧,请问在客户端如何获取这些值? --------------------编程问答-------------------- 还有就是我用的是javaSE编程,不涉及jsp这类的 --------------------编程问答-------------------- 你把代码贴出来看看。。。 --------------------编程问答-------------------- 隐藏 J2SE 搞不明白 看看代码吧 前台和后台都给我丢上来 --------------------编程问答-------------------- hidden 和 text 无任何区别.除了页面上可不可见. --------------------编程问答-------------------- hidden要放在form里一同提交 --------------------编程问答--------------------
<script type="text/javascript" src="/wxmz/JavaScript/Commonfunction.js" charset="UTF-8" language="javascript" ></script><SCRIPT FOR='window' EVENT='onload' LANGUAGE='JavaScript'>document.all.txtPwd.focus();</SCRIPT>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBgLq2sbDBAKQvcXxBwKTlahiAqXVsrMJAtLCmbQIAp37up0OnzWCaI900VaxMj/elPlDvU4UFNE=" />
</div>
<input type="hidden" name="HidName" id="HidName" />
<input type="hidden" name="HidPas" id="HidPas" />
<table id="Table2" height="100%" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" vailgn="middle">
<table id="Table_01" align="center" vailgn="middle" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td height="203" bgcolor="#036CD0">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="751" height="203">
<img src="images/login_01.jpg" border="0" alt="" /></td>
<td width="253">
<img src="images/Login_02.jpg" border="0"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="images/Login_09.jpg">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/Login_05.jpg" width="259" height="309" alt=""></td>
<td width="201" height="309" background="images/Login_06.jpg" align="center">
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td width="24%" height="25">
<img src="Images/login_user.jpg" width="50" height="15"></td>
<td width="51%">
<input name="txtUserName" type="text" value="320203003006" id="txtUserName" tabindex="1" class="inputtxt" style="width:100px;" /></td>
<td width="25%" rowspan="2">
<input type="image" name="Imagebutton1" id="Imagebutton1" tabindex="3" src="Images/btn_login.jpg" style="border-width:0px;" />
</td>
</tr>
<tr align="center" valign="middle">
<td height="25">
<img src="Images/login_psd.jpg" width="50" height="16"></td>
<td>
<input name="txtPwd" type="password" id="txtPwd" tabindex="2" class="inputtxt" style="width:100px;" /></td>
</tr>
</table>
<a href="LoginEpass.aspx"><b>USB加密锁登录</b></a>
</td>
<td>
<img src="images/Login_07.jpg" width="244" height="309" alt=""></td>
<td>
<img src="images/Login_08.jpg" width="293" height="309" alt=""></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="036ACF" height="106">
</td>
</tr>
</table>
</td>
这个是网页登陆源码
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.applet.Applet;
public class t4 extends Applet
{
public static void main(String[] srgs){
t4 t= new t4();
t.loginPluto();
}
public void loginPluto() {
URL url = null;
HttpURLConnection httpurlconnection = null;
try {
url = new URL("http://58.215.18.75:800/wxmz/CustomPlatform/login.aspx");
String strPost = "txtUserName=320203003006&txtPwd=******";
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setInstanceFollowRedirects(true);
httpurlconnection.setDoOutput(true); // 需要向服务器写数据
httpurlconnection.setDoInput(true); //
httpurlconnection.setUseCaches(false); // 获得服务器最新的信息
httpurlconnection.setAllowUserInteraction(false);
httpurlconnection.setRequestMethod("POST");
httpurlconnection
.addRequestProperty(
"Accept",
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-silverlight, */*");
httpurlconnection.setRequestProperty("Accept-Language", "zh-cn");
httpurlconnection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
httpurlconnection.setRequestProperty("Accept-Encoding",
"gzip, deflate");
httpurlconnection
.setRequestProperty(
"User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Foxy/1; .NET CLR 2.0.50727;MEGAUPLOAD 1.0)");
httpurlconnection.setRequestProperty("Content-Length", strPost
.length()
+ "");
httpurlconnection.setRequestProperty("Connection", "Keep-Alive");
httpurlconnection.setRequestProperty("Cache-Control", "no-cache");
// httpurlconnection.setRequestProperty("Cookie", cookie0);
httpurlconnection.getOutputStream().write(strPost.getBytes());
httpurlconnection.getOutputStream().flush();
httpurlconnection.getOutputStream().close();
httpurlconnection.connect();
int code = httpurlconnection.getResponseCode();
// System.out.println("code " + code);
String cookie1 = httpurlconnection.getHeaderField("Set-Cookie");
System.out.print(cookie1);
httpurlconnection.disconnect();
//上面的程序把第一次访问的cookie保存在了cookie1里面
/* url = new URL("http://pluto.whu.edu.cn/users2/userInfoAction.action ");
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setRequestProperty("User-Agent",
"Internet Explorer");
httpurlconnection.setRequestProperty("Cookie", cookie1);
httpurlconnection.connect();
BufferedInputStream urlStream = new BufferedInputStream(httpurlconnection.getInputStream());
Reader r = new InputStreamReader(urlStream, "utf-8");
BufferedReader br = new BufferedReader(r);
StringBuffer strHtml = new StringBuffer("");
String strLine = null;
while ((strLine = br.readLine()) != null) {
strHtml.append(strLine + "\r\n");
}
System.out.print(strHtml.toString());*/
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpurlconnection != null)
httpurlconnection.disconnect();
}
}
}
这个是我自己写的javaSE的代码,在我们自己做的没有隐藏的参数上是可以运行的 --------------------编程问答-------------------- 建议使用httpClient
啥东西都能出来
补充:Java , Web 开发