I have a code that gets a response from the POST request:
//Запрос авторизации бухаря
WebRequest request = WebRequest.Create("http://clannr.org/scripts/login/auth.php");
request.Method = "POST";
string postData = "user=" + Login.Text + "&password=" + Password.Text + "&version=13";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
But when checking the response:
Match match = regex.Match(responseFromServer);
if (match.Success)
{
var input = responseFromServer;
var split = input.Split(':');
var final = split[3];
ProcessStartInfo mcStartInfo = new ProcessStartInfo("javaw", "-Xms1024m -Xmx1024m -cp \"" + appData + "\\.ClanNR\\bin\\minecraft1.jar;" + appData + "\\.ClanNR\\bin\\jinput.jar;" + appData + "\\.ClanNR\\bin\\lwjgl.jar;" + appData + "\\.ClanNR\\bin\\lwjgl_util.jar \" -Djava.library.path=\"" + appData + "\\.ClanNR\\bin\\natives\" net.minecraft.client.Minecraft" + " " + username + " " + final + " " + server1);
Process.Start(mcStartInfo);
this.Close();
}
else if (responseFromServer == " Bad Login")
{
MessageBox.Show("Uncorrect login/password!");
}
else if (responseFromServer == " Old version")
{
MessageBox.Show("Launcher is old!");
}
My code called just 2 functions, i.e. show 2 MessageBox
How to fix it?
UPDATED
Firstly, the
!=
operator means not-equal.Correct me if i'm wrong, but I think you wanted to use
==
.Secondly, you should use else if. if the first condition is true, then it won't check the other.
Because if, say,
responseFromServer
variable equals to"Foo"
then it fits both conditions, because it's not equal to" Bad Login"
and not equal to" Old version"
What you probably want is
else if
:Or probably you wanted
==
instead of!=
So it's your job now to find out what you really want to achieve.
PS: are spaces in the beginning of both strings intended?