0

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 ?

Cumatru
  • 695
  • 2
  • 12
  • 34
  • All HTTP methods have a response. So, your application (whichever method uses) should get something back. – omninonsense Apr 26 '11 at 18:17
  • Ok, but what is the object who holds the response in my case ? And what should i do in the php side ? – Cumatru Apr 26 '11 at 18:23
  • 1
    I don't know Qt, but I I think this line: "QNetworkReply *reply = nwam->post(request,data);" is the answer to your fist question; secondly on the php side you can return anything, really. If you didn't make it 'echo' anything, then it is probably returning an empty string, so try returning anything and see if the contents of 'reply' changes. Also, I think 'data' does nothing (at least in the context it's now), but I' don't know Qt, so I might be wrong. – omninonsense Apr 26 '11 at 18:28

2 Answers2

0

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

snoofkin
  • 8,725
  • 14
  • 49
  • 86
0

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