Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QString Token::obter_token(QString endereco_servidor, QJsonObject dados)
- {
- QUrl url = endereco_servidor;
- url.setPath("/cotacao/Api/login");
- qDebug() << "Key teste";
- QNetworkRequest request(url);
- request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json"));
- QNetworkReply *reply = m_nam->post(request, QJsonDocument(dados).toJson());
- qDebug() << url;
- connect(reply, &QNetworkReply::finished, this, [this, reply] () {
- reply->deleteLater();
- // qDebug() << "todo conteúdo " << reply->readAll();
- const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
- const QJsonObject obj = doc.object();
- if (obj.isEmpty()) {
- qCritical() << "Endereço do Servidor2 não encontrado";
- // return nullptr;
- }
- // qDebug() << obj["upload_data"]["full_path"];
- foreach (const QString &key, obj.keys()) {
- QJsonValue value = obj.value(key);
- // QJsonValue value = obj.value(key)["full_path"];
- if (value.isString()) {
- qDebug() << "Key =" << key << ", Value =" << value.toString();
- } else if (value.isDouble()) {
- qDebug() << "Key =" << key << ", Value =" << value.toInt();
- } else {
- qDebug() << "Key =" << key << ", Value =" << value;
- }
- if (value == "Expired token") {
- qDebug() << "Token expirado";
- qDebug() << "Token" << value.toString();
- // return nullptr;
- // break;
- }
- }
- });
- return nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement