feather/src/utils/networking.cpp

45 lines
1.4 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: BSD-3-Clause
2022-02-10 10:26:41 +00:00
// SPDX-FileCopyrightText: 2020-2022 The Monero Project
#include <QNetworkAccessManager>
#include <QNetworkReply>
2021-07-06 19:36:27 +00:00
#include "utils/Utils.h"
#include "utils/networking.h"
UtilsNetworking::UtilsNetworking(QNetworkAccessManager *networkAccessManager, QObject *parent) :
QObject(parent),
m_networkAccessManager(networkAccessManager) {}
void UtilsNetworking::setUserAgent(const QString &userAgent) {
this->m_userAgent = userAgent;
}
2021-05-02 18:22:38 +00:00
QNetworkReply* UtilsNetworking::get(const QString &url) {
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
2021-05-02 18:22:38 +00:00
return this->m_networkAccessManager->get(request);
}
QNetworkReply* UtilsNetworking::getJson(const QString &url) {
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
request.setRawHeader("Content-Type", "application/json");
return this->m_networkAccessManager->get(request);
}
QNetworkReply* UtilsNetworking::postJson(const QString &url, const QJsonObject &data) {
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
request.setRawHeader("Content-Type", "application/json");
QJsonDocument doc(data);
QByteArray bytes = doc.toJson();
return this->m_networkAccessManager->post(request, bytes);
}