Advertisement
Felipebros

Untitled

May 14th, 2019
1,979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "token.h"
  2.  
  3. #include <QDebug>
  4.  
  5. #include <QNetworkAccessManager>
  6. #include <QNetworkRequest>
  7. #include <QNetworkReply>
  8. #include <QJsonObject>
  9. #include <QJsonDocument>
  10.  
  11. #include "dialog.h"
  12.  
  13. Token::Token() : m_nam(new QNetworkAccessManager(this))
  14. {
  15.  
  16. }
  17.  
  18. void Token::obter_token(QString endereco_servidor, QJsonObject dados)
  19. {
  20.     QUrl url = endereco_servidor;
  21.     url.setPath("/cotacao/Api/login");
  22.     qDebug() << "Key teste";
  23.  
  24.     QNetworkRequest request(url);
  25.     request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json"));
  26.  
  27.     QNetworkReply *reply = m_nam->post(request, QJsonDocument(dados).toJson());
  28.     qDebug() << url;
  29.  
  30.     connect(reply, &QNetworkReply::finished, this, &Token::fim_token);
  31.  
  32. }
  33.  
  34. void Token::fim_token()
  35. {
  36.     QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
  37.  
  38.     const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
  39.     const QJsonObject obj = doc.object();
  40.     qDebug() << "obj" << obj;
  41.     qDebug() << "fim token2";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement