Advertisement
Felipebros

Untitled

May 13th, 2019
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. QString Token::obter_token(QString endereco_servidor, QJsonObject dados)
  2. {
  3.     QUrl url = endereco_servidor;
  4.     url.setPath("/cotacao/Api/login");
  5.     qDebug() << "Key teste";
  6.  
  7.     QNetworkRequest request(url);
  8.     request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json"));
  9.  
  10.     QNetworkReply *reply = m_nam->post(request, QJsonDocument(dados).toJson());
  11.     qDebug() << url;
  12.  
  13.  
  14.     connect(reply, &QNetworkReply::finished, this, [this, reply] () {
  15.         reply->deleteLater();
  16.         //        qDebug() << "todo conteúdo " << reply->readAll();
  17.         const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
  18.         const QJsonObject obj = doc.object();
  19.         if (obj.isEmpty()) {
  20.             qCritical() << "Endereço do Servidor2 não encontrado";
  21. //            return nullptr;
  22.         }
  23.         //        qDebug() << obj["upload_data"]["full_path"];
  24.         foreach (const QString &key, obj.keys()) {
  25.             QJsonValue value = obj.value(key);
  26.             //            QJsonValue value = obj.value(key)["full_path"];
  27.             if (value.isString()) {
  28.                 qDebug() << "Key =" << key << ", Value =" << value.toString();
  29.             } else if (value.isDouble()) {
  30.                 qDebug() << "Key =" << key << ", Value =" << value.toInt();
  31.             } else {
  32.                 qDebug() << "Key =" << key << ", Value =" << value;
  33.             }
  34.             if (value == "Expired token") {
  35.                 qDebug() << "Token expirado";
  36.                 qDebug() << "Token" << value.toString();
  37. //                return nullptr;
  38.                 //                break;
  39.             }
  40.         }
  41.  
  42.     });
  43.  
  44.     return nullptr;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement