How to send data back from PHP after a HTTP Post i

2019-08-27 11:27发布

问题:

I'm using this code to make a simple HTTP Post ( a login )

   QNetworkAccessManager *nwam = new QNetworkAccessManager;

   QNetworkRequest request(QUrl("http://localhost/laptop/trylogin.php"));

   QByteArray data;
   QUrl params;

   QString userString(user);
   QString passString(pass);

   params.addQueryItem("user", userString );
   params.addQueryItem("pass", passString );
   data.append(params.toString());
   data.remove(0,1);

   QNetworkReply *reply = nwam->post(request,data);

If the logging succeedes or not, how do i send and read the response in Qt ?

回答1:

You get the response / reply in the reply pointer. Use QNetworkReply::error() to see if there was an error.



回答2:

You can catch reply signals cause it works with Signals and slots.. So you have to connect a slot to the signal httpreadyread emitted by reply and then read the reply by reply.readAll method.. READ qtnetwork module documentation..