这是我的Qt创建者代码,用于将数据发送到PHP服务器并获得响应。
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkAccessManager::connect(manager, SIGNAL(finished(QNetworkReply*)),this , SLOT(replyFinished(QNetworkReply*)));
QNetworkRequest *request = new QNetworkRequest(QUrl("http://68.169.55.41/fss/verifylogindetails.php"));
QByteArray postData ="{\"estate_id\":\"hsr\",\"emp_pin\":1234,\"emp_id\":\"santhosh\"}";
request->setRawHeader( "User-Agent" , "Mozilla Firefox" );
request->setRawHeader( "charset", "utf-8" );
request->setRawHeader( "Connection", "keep-alive" );
manager->post(*request, postData );
}
void MainWindow::replyFinished(QNetworkReply *reply)
{
QString data = reply->readAll().trimmed();
qDebug() << data;
}
这是我的php代码,用于接收登录数据并与数据库值进行比较并发送响应。
<?php
include 'config.php';
$data = json_decode($_SERVER['HTTP_JSON']);
$con = mysql_connect($host, $user_name, $password);
if (!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db($db_name, $con);
$result = mysql_query("SELECT * FROM login_data_table");
while($row = mysql_fetch_array($result))
{
if((strcasecmp( $row['Emp_Id'], $data->emp_id) == 0) && ($row['Emp_Pin'] == $data->emp_pin) && (strcasecmp( $row['Estate_Id'], $data->estate_id) == 0))
{
echo "SUCCESS";
}
else
{
echo "FAIL";
}
}
mysql_close($con);
?>
我的问题是...... 我总是从服务器收到FAIL消息。即使我发送正确的登录详细信息。 请帮助我在我的代码中出错。