I am having a trouble with the boolean. I am trying to get access to my website script and see if it have response through the httpwebrequest method, then check if the bool is valid then login to the system to receive the information.
private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
//Address of URL
String ^URL = "http://www.mysite.com/myscript.php?user=" + TextBox1->Text + "&pass=" + TextBox2->Text;
HttpWebRequest ^request = safe_cast<HttpWebRequest^>(WebRequest::Create(URL));
HttpWebResponse ^response = safe_cast<HttpWebResponse^>(request->GetResponse());
StreamReader ^reader = gcnew StreamReader(response->GetResponseStream());
String ^str = reader->ReadToEnd();
<br/>
if (request->HaveResponse)
{
MessageBox::Show("connected ok, now let login!");
try
{
//Address of URL
String ^URL1 = "http://www.mysite.com/myscript.php?user=" + TextBox1->Text + "&pass=" + TextBox2->Text;
HttpWebRequest ^request1 = safe_cast<HttpWebRequest^>(WebRequest::Create(URL1));
HttpWebResponse ^response1 = safe_cast<HttpWebResponse^>(request1->GetResponse());
StreamReader ^reader1 = gcnew StreamReader(response1->GetResponseStream());
String ^str1 = reader1->ReadToEnd();
//Do login stuff here.
bool login = false;
//User Login
login = true;
if (str == login)
{
MessageBox::Show("You are now login!");
//Check if two users are login at the same time.
bool checklogin = false;
}
}
}
}
The arguments are jumping on the statement of if (str == login). I have got two errors which it is:
Error: error C2446: '==' : no conversion from 'int' to 'System::String ^'
Error: error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int'
I have used the statement as if (str ==login.ToString()), but I did not get the return argument. I have tried to use each different properties, but there are still variable and I still has no return argument. What I am trying to do is to get access to the website, check if the login details is valid then display the messagebox that says "You are now login!".
As the error says, str is a managed pointer to a System::String (IIRC) and login is a bool, so you can't compare them with ==. What kind of comparison are you trying to make?