How to send data back from PHP after a HTTP Post in Qt?

北城以北 提交于 2019-12-12 02:02:32

问题


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..



来源:https://stackoverflow.com/questions/5794600/how-to-send-data-back-from-php-after-a-http-post-in-qt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!