Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "token.h"
- #include <QDebug>
- #include <QNetworkAccessManager>
- #include <QNetworkRequest>
- #include <QNetworkReply>
- #include <QJsonObject>
- #include <QJsonDocument>
- #include "dialog.h"
- Token::Token() : m_nam(new QNetworkAccessManager(this))
- {
- }
- void 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, &Token::fim_token);
- }
- void Token::fim_token()
- {
- QNetworkReply * reply = qobject_cast<QNetworkReply *>(sender());
- const QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
- const QJsonObject obj = doc.object();
- qDebug() << "obj" << obj;
- qDebug() << "fim token2";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement