Trying to post the paramaters onto the server but have no avail(following is my folder)
My file resides(my local host == C:\wamp\www)
https://farm4.staticflickr.com/3544/...ff858f14_c.jpg
bridge.html
<html>
<form action="general_query.php" method="post">
<input type="text" name="db_server">
<input type="text" name="db_user">
<input type="text" name="db_password">
<input type="text" name="db_database">
<input type="text" name="query_message">
</form>
</html>
<html>
<form action="general_query.php" method="post">
<input type="text" name="db_server">
<input type="text" name="db_user">
<input type="text" name="db_password">
<input type="text" name="db_database">
<input type="text" name="query_message">
</form>
</html>
To copy to clipboard, switch view to plain text mode
general_query.php
<?php
$response = array();
$response["server"] = _$POST['db_server'];
$response["user"] = _$POST['db_user'];
$response["password"] = _$POST['db_password'];
$response["db"] = _$POST['db_database'];
$response["query_message"] = _$POST['query_message'];
echo($response);
?>
<?php
$response = array();
$response["server"] = _$POST['db_server'];
$response["user"] = _$POST['db_user'];
$response["password"] = _$POST['db_password'];
$response["db"] = _$POST['db_database'];
$response["query_message"] = _$POST['query_message'];
echo($response);
?>
To copy to clipboard, switch view to plain text mode
main.cpp
#include "MainWindow.hpp"
#include <QApplication>
#include <QDebug>
#include <QByteArray>
#include <QEventLoop>
#include <QNetworkReply>
#include <QTextCodec>
#include <QUrl>
#include <QUrlQuery>
int main(int argc, char *argv[])
{
QNetworkRequest request("http://127.0.0.1/bridge/bridge.html");
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
QUrlQuery query;
query.addQueryItem("db_database", "a");
query.addQueryItem("db_password", "b");
query.addQueryItem("db_server", "c");
query.addQueryItem("db_user", "d");
query.addQueryItem("query_message", "e");
post_data.setQuery(query);
QNetworkAccessManager network_manager;
auto network_reply = network_manager.post(request,
query.query().toUtf8());
connect(network_reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if(network_reply->error() == QNetworkReply::NoError){
raw_data = network_reply->readAll();
}else{
qDebug()<<network_reply->errorString();
}
qDebug()<<QTextCodec::codecForHtml(raw_data)->toUnicode(raw_data);
}
#include "MainWindow.hpp"
#include <QApplication>
#include <QDebug>
#include <QByteArray>
#include <QEventLoop>
#include <QNetworkReply>
#include <QTextCodec>
#include <QUrl>
#include <QUrlQuery>
int main(int argc, char *argv[])
{
QNetworkRequest request("http://127.0.0.1/bridge/bridge.html");
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
QUrlQuery query;
query.addQueryItem("db_database", "a");
query.addQueryItem("db_password", "b");
query.addQueryItem("db_server", "c");
query.addQueryItem("db_user", "d");
query.addQueryItem("query_message", "e");
QUrl post_data;
post_data.setQuery(query);
QNetworkAccessManager network_manager;
auto network_reply = network_manager.post(request,
query.query().toUtf8());
QEventLoop loop;
connect(network_reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QByteArray raw_data;
if(network_reply->error() == QNetworkReply::NoError){
raw_data = network_reply->readAll();
}else{
qDebug()<<network_reply->errorString();
}
qDebug()<<QTextCodec::codecForHtml(raw_data)->toUnicode(raw_data);
}
To copy to clipboard, switch view to plain text mode
The results are same as the texts of the bridge.html but not the json as I expected
expected results
{
"server": "c"
"user": "d"
"password": "b"
"db": "a"
"query message": "e"
}
{
"server": "c"
"user": "d"
"password": "b"
"db": "a"
"query message": "e"
}
To copy to clipboard, switch view to plain text mode
Bookmarks