Hello wysota
In the first method takeId i make a GET request to take an id like :c9A188DB9-048B-8F48-0B65-D696212D9AF2_k7D5BBE5A-A72E-33F9-38AD-7C37C4146126

In the takeCookie method i made a cookie in write in my cookie file :
Sun, 12-Aug-2012 17:59:28 GMT; domain=cas.univ-ubs.fr; path=/c9A188DB9-048B-8F48-0B65-D696212D9AF2_k7D5BBE5A-A72E-33F9-38AD-7C37C4146126

next i make a POST request for login with my first cookie, my username, the id, and my password but nothing append.

in firefox when i just go in the web i receveid a cookie but in qt i can't so i simulated the first cookie.

In python a similar code work perfectly then i think i just a little error in my code.
Qt Code:
  1. void FenPrincipale::takeId()
  2. {
  3. QNetworkAccessManager *m = new QNetworkAccessManager();
  4. QNetworkRequest requete(QUrl("https://cas.univ-ubs.fr/login"));
  5.  
  6. QNetworkReply *r = m->get(requete);
  7. qDebug() << "takeId";
  8.  
  9. connect(r, SIGNAL(finished()), this, SLOT(takeCookies()));
  10. connect(r, SIGNAL(error(QNetworkReply::NetworkError)), this,
  11. SLOT(messageErreur(QNetworkReply::NetworkError)));
  12.  
  13. }
  14.  
  15. void FenPrincipale::takeCookies()
  16. {
  17. boutonEnvoyer->setEnabled(false);
  18.  
  19.  
  20. QNetworkReply *reply = static_cast<QNetworkReply*>(sender());
  21. QNetworkAccessManager *m = reply->manager();
  22.  
  23. // Récupère L'id
  24. QString source = reply->readAll();
  25. QString lt = source.section("\"",119,119);
  26. // Récupère le Cookie JSession
  27. source = source.section("\"",41,41);
  28. // Contruit le cookie
  29. QString data;
  30. data = "JSESSIONID";
  31. data += source.remove(QRegExp("[a-z/;]"));
  32. data += "; expires=Sun, 12-Aug-2012 17:59:28 GMT; domain=cas.univ-ubs.fr; path=/";
  33.  
  34. qDebug() << "takeCookies =" << data;
  35.  
  36. QFile f("Cookies.txt");
  37. QTextStream out(&f);
  38. if ( f.open(QIODevice::ReadWrite) )
  39. {
  40. QString exist = out.readAll();
  41. if (exist.indexOf("cas") != -1 )
  42. {
  43. out.seek(0);
  44. qDebug() << "seek";
  45. }
  46.  
  47. out << data;
  48. f.close();
  49. }
  50. m->setCookieJar(new CookieJar(this));
  51.  
  52. QUrl postData;
  53. postData.addQueryItem("username","");
  54. postData.addQueryItem("password",var2_Edit->text());
  55. postData.addQueryItem("warn", "true");
  56. postData.addQueryItem("lt", lt);
  57. postData.addQueryItem("_eventId", "submit");
  58. postData.addQueryItem("submit", "SE CONNECTER");
  59.  
  60. // On crée une requête
  61. QNetworkRequest requete(QUrl(urlEdit1->text()));
  62.  
  63. QNetworkReply *r;
  64. if (box2->isChecked())
  65. {
  66. requete.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
  67. r = m->post(requete, postData.encodedQuery());
  68. }
  69.  
  70. // Gestion des erreurs
  71. connect(r, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(messageErreur(QNetworkReply::NetworkError)));
  72. // Gestion de fin de téléchargement
  73. connect(r, SIGNAL(finished()), this, SLOT(takeLink()));
  74.  
  75. // Gestion de la barre de progression
  76. connect(r, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(progressionTelechargement(qint64, qint64)));
  77.  
  78. connect(r, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(ErreurSsl(const QList<QSslError>&)));
  79.  
  80. connect(m, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
  81. this,SLOT(authentification(QNetworkReply*, QAuthenticator*)));
  82.  
  83. }
  84.  
  85. void FenPrincipale::takeLink()
  86. {
  87. QNetworkReply *reply = static_cast<QNetworkReply*>(sender());
  88. QNetworkAccessManager *m = reply->manager();
  89. m->setCookieJar(new CookieJar(this));
  90.  
  91. qDebug() << reply->readAll();
  92. boutonEnvoyer->setEnabled(true);
  93.  
  94. QNetworkRequest requete(QUrl("http://web.univ-ubs.fr/edt/ade/custom/myplanning/myPlanning.jsp?top=top.moniframeesup"));
  95. QNetworkReply *r = m->get(requete);
  96. qDebug() << "takeLink";
  97. }
To copy to clipboard, switch view to plain text mode