110,533
社区成员
发帖
与我相关
我的任务
分享
StreamReader sr = new StreamReader(@"C:\Users\Administrator\Desktop\test.txt",System.Text.Encoding.Default);
string str = sr.ReadToEnd();
string result = "";
string flagstr = "name=\"struts.token.name\" value=\"";
int beginIndex = str.IndexOf(flagstr);
if (beginIndex > -1)
{
int endIndex = str.IndexOf("\" />", beginIndex);
result = str.Substring(beginIndex + flagstr.Length, endIndex - beginIndex -flagstr.Length);
}
差别就是 将
int endIndex=str.IndexOf("\"/>",beginIndex);
变更为了如下(多了个空格)
int endIndex = str.IndexOf("\" />", beginIndex);
我这已经得到了struts.token
public string value = "";
string value2 = "value=\"";
private void button1_Click(object sender, EventArgs e)
{
value = this.textBox1.Text;
this.textBox1.Text = value.Substring(value.IndexOf(value2) + value2.Length, value.LastIndexOf("\"") - value.IndexOf("value=\"") - value2.Length);
}
private void Form2_Load(object sender, EventArgs e)
{
this.textBox1.Text = "<input type=\"hidden\" name=\"struts.token.name\" value=\"你个2HUO\"/>";
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<title>卧龙吟大型战争策略型网页游戏</title>
<meta http-equiv="keywords" content="3yx卧龙吟,卧龙吟官网,官方卧龙吟,卧龙吟,网页游戏,三国网游,策略游戏,三国游戏,卧龙吟攻略,卧龙吟金币,人最多的卧龙吟" />
<link href="/css/login.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function CheckLogin() {
var username=$("#username").val();
if (username == "") {
alert("请输入用户名!");
$("#username").focus();
return false;
}
var pswd=$("#pswd").val();
if (pswd=="") {
alert("密码不能为空!");
$("#pswd").focus();
return false;
}
$("#form1").submit();
}
function AddFavorite(sURL, sTitle){
try{
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e){
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
$(document).ready(function ()
{
if($.trim("") != "")
{
alert("用户名或密码错误");
window.location.href="http://www.wolongyin.com:80/loginGame.jsp?sid="+$("#sid").val();
}
if($.trim("") != "")
{
$("#sid").val('');
}
});
$(document).keypress(function(e){if(e.keyCode==13){CheckLogin();}});
</script>
</head>
<body>
<form id="form1" name="form1" action="checkGameLogin.xhtml;jsessionid=54218ABEA8C930D39F5A91F0C5E566C9.tomcat1" method="post">
<table class="wwFormTable">
<input name="sid" id="sid" type="hidden" value="1002"/>
<input type="hidden" name="struts.token.name" value="struts.token" />
<input type="hidden" name="struts.token" value="NM1L6FX1ZVV8LKHQBKPAQOSEZHK3DQVK" />
<div class="warp">
<div class="login_l">
<div class="l01"></div>
<div class="l02"></div>
<div class="l03"></div>
<div class="l04"></div>
<div class="l05"></div>
<div class="l06"></div>
</div>
<div class="login_r">
<div class="r01"></div>
<div class="r02"></div>
<div class="r03"></div>
<div class="r04"></div>
<div class="r05">
<div class="clear"></div>
<div class="login_box">
<br />
<input type="hidden" name="act" value="login" />
<p>
<label for="username">
用户名:
</label>
<input type="text" name="username" id="username" class="t_input" value="" maxlength="26"/>
</p>
<p>
<label for="password">
密 码:
</label>
<input type="password" name="password" id="pswd" class="t_input" value="" maxlength="26"/>
</p>
</div>
</div>
<div class="r06">
<div class="clear"></div>
<div class="login_box3">
<p>
<input type="button" class="loginbtn" value="" onclick="return CheckLogin();" />
<a href="http://www.youxila.com/recharge/toChooseRechargeManner.xhtml?gameid=1" class="paybtn" target="_blank"></a>
</p>
</div>
</div>
<div class="r07">
<div class="clear"></div>
<div class="login_box2">
<p>
<a href="/" target="_blank">官方网站</a> |
<a href="http://www.youxila.com/page/front/regWly.jsp" target="_blank">帐号注册</a> |
<a href="http://www.youxila.com/page/front/person/person_repassword_1.jsp" target="_blank">找回密码</a>
|
<a onclick="AddFavorite(window.location,document.title)" >加入收藏</a>
</p>
</div>
</div>
<div class="r08"></div>
</div>
<div class="clear"></div>
<div class="tips">
玩法多样的战争策略,属性随机的神兵利器,彼此克制的各系兵种,纯正绿色的页游模式让您体验最纯粹的史诗级战争三国题材游戏巨作。
<br />
抵制不良游戏,拒绝盗版游戏。注意自我保护,谨防受骗上当。适度游戏益脑,沉迷游戏伤身。合理安排时间,享受健康生活。
<br />
<a href="http://www.3yx.com" target="_blank">3YX(上游戏服务网)</a> 为您呈上好游戏 卧龙吟
<br />
Copyright © 3YX卧龙吟 版权所有
</div>
</div>
</table></form>
</body>
</html>
string str="<input type=\"hidden\" name=\"struts.token.name\" value=\"123456\"/>";
string result = "";
string flagstr = "name=\"struts.token.name\" value=\"";
int beginIndex = str.IndexOf(flagstr);
if (beginIndex > -1)
{
int endIndex=str.IndexOf("\"/>",beginIndex);
result = str.Substring(beginIndex + flagstr.Length, endIndex - beginIndex -flagstr.Length);
}
这是字符串截取的方法
建议使用正则