WebRequest和标签中的数据
本文关键字:数据 标签 WebRequest | 更新日期: 2023-09-27 18:26:34
我在PHP MySql上创建了授权,它运行良好。我想这一切都破坏了TextBox。这是我的PHP代码。没有错误。
<?php
include('../functions.php'); // connect mysqli
if ($_POST['form_name'] == 'loginform') {
$crypt_pass = md5($_POST['password']);
$found = false;
$res = $mysqli->query("SELECT password FROM accounts WHERE username = '".$mysqli->real_escape_string($_POST['username'])."'");
if ($data = $res->fetch_array()) {
if ($crypt_pass == $data['password']) {
$found = true;
}
}
if ($found == false) {
echo 'LoginFail';
}
else {
echo 'LoginOK';
}
}
?>
我的WebRequest:
WebRequest request = WebRequest.Create("http://unknow.com/user/login2.php");
request.Method = "POST";
string postData = "form_name=loginform&username=" + LoginInput +
"&password=" + PasswordInput;
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();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
response_label.Text = responseFromServer;
reader.Close();
dataStream.Close();
response.Close();
当这个代码好的时候,PHP告诉我"LoginOK":
string postData="form_name=loginform&username=snosme&password=123456";
但当代码:
string postData = "form_name=loginform&username=" + LoginInput +
"&password=" + PasswordInput;
PHP告诉我登录失败。尽管我在TextBox中输入了相同的数据。怎么了?
看到您的图像后,我认为问题是您忘记了在文本字段中获取Text值。试试这个:
string postData = "form_name=loginform&username=" + LoginInput.Text +
"&password=" + PasswordInput.Text;