下面是我抓OA的一个登陆网页的一个提交表单,我能否写个JAVA应用程序通过socket或者什么http之类的东西来在我的应用程序里面提交账号和密码,我的目的是抓他返回的页面内容,然后做分析。<form onsubmit="var languages=window.document.all.languages.value;
var Curname=document.forms[0].Username.value;
var Password=document.forms[0].Password.value;
document.cookie = "A=" + Curname;
document.cookie = "B=" + Password;
//设置最后访问人
var cookieExpires
var expdate = new Date();
expdate.setTime(expdate.getTime() + 30 * (24 * 60 * 60 * 1000));
cookieExpires = expdate.toGMTString();
if (languages!=""){
document.cookie = "LN="+languages+ ";expires=" + cookieExpires;
}
document.cookie = "LastVisitUserName=" + Curname + ";expires=" + cookieExpires;
return true;" method="post" action="/names.nsf?Login" name="_DominoForm">
var Curname=document.forms[0].Username.value;
var Password=document.forms[0].Password.value;
document.cookie = "A=" + Curname;
document.cookie = "B=" + Password;
//设置最后访问人
var cookieExpires
var expdate = new Date();
expdate.setTime(expdate.getTime() + 30 * (24 * 60 * 60 * 1000));
cookieExpires = expdate.toGMTString();
if (languages!=""){
document.cookie = "LN="+languages+ ";expires=" + cookieExpires;
}
document.cookie = "LastVisitUserName=" + Curname + ";expires=" + cookieExpires;
return true;" method="post" action="/names.nsf?Login" name="_DominoForm">
解决方案 »
- 关于JDBC连接数据库时出现“数据传送至后端发生IO错误”问题
- 求大神,用分而治之算法写归并排序的理解
- 谁用过SQLJ..? 帮给解释下呗
- 请教高手如何用JAVASCRIPT判断本地文件是否存在
- hql日期比较问题,请拼出语句
- MyEclipse8.6怎么配置Access数据库连接?
- ireport的一个问题,请大家看一下
- 为何直接打开连接applet的html文件,applet不能运行,而在jbuilder却可以?
- 求教用java编写TicTacToe网络游戏(simple)的,散500分!
- 请问哪里有install anywhere下载,或者发一份给我也可以,我找了好久都没找到!
- 求教小问题(boolean赋值问题)
- 关于链表排序
String currname = ""; //提交的用户名
String currpwd = ""; //提交的秘密
//post的数据,其中的Username 和 Password 是表单上input的name属性名,大小写必须一致
String postdata = "Username=" + URLEncoder.encode(currname,"utf-8") +"&Password=" + URLEncoder.encode(currpwd, "utf-8");
URL url = new URL("http://localhost/xxx/names.nsf?Login"); //提交的地址
//STEP.1.建立连接
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST"); //设置方法为Post
//STEP.2.设置Cookie 根据你的js做的
con.setRequestProperty("Cookie", "A="+currname+"; B="+currpwd+"; LastVisitUserName=" + currname +";");
//STEP.3.发送post数据
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(con.getOutputStream()));
writer.write(postdata);
writer.flush();
writer.close();
//STEP.4.获取返回数据
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
con.disconnect();
代码已贴出,根据你的描述 写的这段代码绝对没问题,但是你是否能模拟成功,跟你模拟的网页操作是否一致有关建议用 httpAnalyzer 或 httpWatch 监听下 需要设置什么(比如referer,一些特殊的header)一目了然不懂工具怎么用 百度一下