C# 名称';登陆';在当前上下文中不存在
我只是尝试为travian创建bot,我找到了一些登录代码C# 名称';登陆';在当前上下文中不存在,c#,.net,C#,.net,我只是尝试为travian创建bot,我找到了一些登录代码 //download html WebClient client = new WebClient(); client.Encoding = System.Text.Encoding.UTF8; string source = client.DownloadString(@"Http://" + server + "/login.php"); source
//download html
WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
string source = client.DownloadString(@"Http://" + server + "/login.php");
source = source.Replace("\"", "");
//search for user
Regex rloginName = new Regex(@"name=login value=\w*");
Match mloginName = rloginName.Match(source);
if (mloginName.Success)
{
string loginName = mloginName.ToString().Replace(@"name=login value=", "");
}
//search for pass
Regex rloginPassword = new Regex(@"type=password name=\w*");
Match mloginPassword = rloginPassword.Match(source);
if (mloginPassword.Success)
{
string loginPassword = mloginPassword.ToString().Replace(@"type=password name=", "");
}
Regex rloginUsername = new Regex(@"input class=fm fm110 type=text name=\w*");
Match mloginUsername = rloginUsername.Match(source);
if (mloginUsername.Success)
{
string loginUsername = mloginUsername.ToString().Replace(@"input class=fm fm110 type=text name=", "");
}
Regex rloginRand = new Regex(@"<p align=center><input type=hidden name=\w*");
Match mloginRand = rloginRand.Match(source);
if (mloginRand.Success)
{
string loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=", "");
}
string postString = @"w=1024:768&login=" + loginName + "&" + loginUsername + "=" + user + "&" + loginPassword + "=" + pass + "&" + loginrand + "=&s1.x=10&s1.y=10&s1=login";
WebRequest req = WebRequest.Create(@"http://" + server + "/dorf1.php");
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postString);
req.ContentLength = bytes.Length;
req.ContentLength = bytes.Length;
Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader(resp.GetResponseStream());
中央处理器------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe
/noconfig/nowarn:17011702
/错误报告:提示/警告:4
/定义:调试;痕迹
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.WINDOWS.Forms.dll
/参考:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll
/调试+/调试:完全/优化-
/输出:obj\Debug\travian-ah.exe
/资源:obj\Debug\travian_ah.Form1.resources
/资源:obj\Debug\travian\u ah.Properties.Resources.Resources
/目标:winexe Form1.cs
Form1.Designer.cs Program.cs
属性\AssemblyInfo.cs
属性\Resources.Designer.cs
属性\Settings.Designer.cs
C:\Documents and Settings\My
文档\ Visual Studio
2005\Projects\travian ah\travian ah\Form1.cs(33,64):
错误CS0165:使用未分配的本地
变量“server”C:\Documents和
设置\我的文档\ Visual Studio
2005\Projects\travian ah\travian ah\Form1.cs(70,56):
错误CS0165:使用未分配的本地
变量“loginName”C:\Documents和
设置\我的文档\ Visual Studio
2005\Projects\travian ah\travian ah\Form1.cs(70,74):
错误CS0165:使用未分配的本地
变量“loginUsername”C:\Documents
和设置\My Documents\Visual
演播室
2005\Projects\travian ah\travian ah\Form1.cs(70,96):
错误CS0165:使用未分配的本地
变量“user”C:\Documents和
设置\我的文档\ Visual Studio
2005\Projects\travian ah\travian ah\Form1.cs(70109):
错误CS0165:使用未分配的本地
变量“loginPassword”C:\Documents
和设置\My Documents\Visual
演播室
2005\Projects\travian ah\travian ah\Form1.cs(70131):
错误CS0165:使用未分配的本地
变量“pass”C:\Documents和
设置\我的文档\ Visual Studio
2005\Projects\travian ah\travian ah\Form1.cs(70144):
错误CS0165:使用未分配的本地
变量“loginrand”
这些变量是在IF块中声明的,因此它们只在IF块中已知。在if块之前声明它们,例如:
string loginrand;
if (mloginRand.Success)
{
loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=", "");
}
if (mloginPassword.Success)
{
// variable defined here
string loginPassword =
mloginPassword.ToString().Replace(@"type=password name=", "");
}
// variable not available here
stringloginrand;
if(mloginRand.Success)
{
loginrand=mloginRand.ToString().Replace(“这些变量在IF块中声明,因此它们仅在IF块中已知。在IF块之前声明它们,例如:
string loginrand;
if (mloginRand.Success)
{
loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=", "");
}
if (mloginPassword.Success)
{
// variable defined here
string loginPassword =
mloginPassword.ToString().Replace(@"type=password name=", "");
}
// variable not available here
stringloginrand;
if(mloginRand.Success)
{
loginrand=mloginRand.ToString()。替换(“
不要烦人,为在线游戏创建机器人
了解变量作用域,在if语句中声明变量意味着该变量在其外部不可用
例如:
string loginrand;
if (mloginRand.Success)
{
loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=", "");
}
if (mloginPassword.Success)
{
// variable defined here
string loginPassword =
mloginPassword.ToString().Replace(@"type=password name=", "");
}
// variable not available here
不要烦人,为在线游戏创建机器人
了解变量作用域,在if语句中声明变量意味着该变量在其外部不可用
例如:
string loginrand;
if (mloginRand.Success)
{
loginrand = mloginRand.ToString().Replace("<p align=center><input type=hidden name=", "");
}
if (mloginPassword.Success)
{
// variable defined here
string loginPassword =
mloginPassword.ToString().Replace(@"type=password name=", "");
}
// variable not available here
您正在围绕这些字符串的if块范围内定义这些字符串。退出if,您也会删除字符串
只需将这些字符串的声明移到代码的顶部。您是在围绕它们的if块的范围内定义这些字符串。退出if,您也会删除字符串
只需将这些声明移到代码的顶部。对于明确分配,您需要字符串loginrand=“”;
对于明确分配,您需要字符串loginrand=“”;
这不值得否决(或否决)即使在你眼中这是一个愚蠢的问题。如果你没有任何编程经验,即使你没有编写你要问的代码,你也不应该发布问题。来吧,伙计们不要粗鲁。这不值得被否决(或否决)即使在你看来这是一个愚蠢的问题。如果你没有任何编程经验,即使你没有编写你要问的代码,你也应该能够发布问题。来吧,伙计们不要粗鲁。同意,第一点很好。但是通过StackOverflow学习变量作用域而不是在书中阅读它有什么问题吗这是一个编程问题,不是吗?;)同意,好的第一点。但是通过StackOverflow学习变量作用域,而不是在书中阅读,这是一个编程问题,不是吗?;)